Resolve dependency in a specific module

Topics: Core, Customizing Orchard, Writing modules
Aug 19, 2013 at 12:36 PM
Hi,

Is it possible to resolve an interface in a specific module knowing its name ?

Thanks
Developer
Aug 19, 2013 at 10:24 PM
Not by default, unless you're able to acquire the actual type, which means you need to either
  • know the Fully Qualified Assembly Name, not the interface name alone or
  • scan all loaded assemblies and search for the interface type by name (huge perf hit)
Having the type in hand you can use ILifetimeScope or IComponentContext dependency and call Resolve(<type>) to get the instance.

For custom dependencies you could also use the Autofac's named registrations feature, register your types with the interface name and then use ResolveNamed on one of the objects described above. You won't be able to resolve any core Orchard dependencies this way though.
Aug 22, 2013 at 3:31 PM
Thanks for your answer.

I did it this way :
  • I put a GetModuleName() method in my interface IAppContextProvider.
  • Then y injected in my widget constructor an IEnumerable<IAppContextProvider>.
  • I created a dictionary with each implementation as a value and the name I got from each one as a key.
  • And now my widget is able to request the context from the interface of the current module name (the area part of the request).