Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access overall AutoFac container to register a dependency in Orchard?

the question is pretty straightforward.i want to access overall AutoFac container so that i can register my dependency in it.

remark:

i am not OK with inheriting from IDependency cause in my project it results in a circular referencing (of two assemblies).what i wanna do is register a component with a Key and access it with same Key in other assembly. thanks in advance.

EDIT:

i have found a class called DefaultOrchardHostContainer in the core ,but it only exposes Resolve<> method but not Register().

like image 552
Behnam Esmaili Avatar asked Nov 27 '12 12:11

Behnam Esmaili


People also ask

How do I get Autofac containers?

From Visual Studio, you can get it via NuGet. The package name is Autofac. Alternatively, the NuGet package can be downloaded from the GitHub repository (https://github.com/autofac/Autofac/releases).

What is Autofac container?

Autofac is an addictive IoC container for . NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. This is achieved by treating regular . NET classes as components.


1 Answers

You can add an Autofac module directly to your Orchard module and Orchard will pick it up. ex...

public class MyModule : Module {
   protected override void Load(ContainerBuilder builder){
      builder.RegisterType<MyDependency>().As<IMyDependency>().InstancePerDependency();
   }
}
like image 101
Brandon Joyce Avatar answered Nov 15 '22 09:11

Brandon Joyce