This project is read-only.

Why need inherit from IDependency, but not register it with autofac?

Topics: Customizing Orchard, Troubleshooting, Writing modules
Jul 24, 2011 at 2:33 AM


  I am reading the source code,  and find many class inherit from IDependency,ISingletonDependency,IUnitOfWorkDependency or ITransientDependency.   but why not use autofac directly? 

(such as: builder.RegisterType<DefaultCacheHolder>().As<ICacheHolder>().SingleInstance();)


                          foreach (var interfaceType in item.Type.GetInterfaces()
                            .Where(itf => typeof(IDependency).IsAssignableFrom(itf)
                                      && !typeof(IEventHandler).IsAssignableFrom(itf))) {
                            registration = registration.As(interfaceType);
                            if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType)) {
                                registration = registration.InstancePerMatchingLifetimeScope("shell");
                            else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType)) {
                                registration = registration.InstancePerMatchingLifetimeScope("work");
                            else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType)) {
                                registration = registration.InstancePerDependency();



Jul 25, 2011 at 9:13 PM

Because it is not the responsibility of the implementer of that class to decide when it should register itself with Autofac. We have a distinct container per tenant, and rules about the order of preference between modules. In other words it's much more complicated than that.

Also, implementing IDependency is a lot easier and light in terms of concept count.