Search code examples
c#.netorchardcmsorchardcms-1.8

Orchard CMS - Preferred method for feature switching when not using IDependency


I want to feature switch a service implementation. This is easy to do by making Interfaces inherit IDependency and simply marking implementation with:

[OrchardFeature("MyFeature")]
[OrchardSuppressDependency("MyService1")]

There are a couple of reasons I can't use IDependency for this:

  • I need to inject a named service into my implementations
  • Interceptors need to be used with the services

Therefore, the implementations need to have an explicit autofac registration. To feature switch, I need to create 2 autofac registration modules and feature switch them.

My question is: Is this the preferred method? Is there another way that you can suggest to feature switch these autofac registrations?


Solution

  • Custom Autofac module is indeed the preferred way in case you need to do more complex registrations (like named or intercepted ones etc.). We use those a lot in Orchard core.

    Autofac module in Orchard can be the subject to OrchardFeature as well as OrchardSuppressDependency attributes, making it a pretty powerful and easy to use solution when customization is required.