Dependency resolution as a separate project. How?

I am creating a new application using asp.net mvc, I am using the IOC munq container as my dependency injection. The problem is that I want to create a new project for resolving dependencies, where I can register all the mvc project controllers and the infrastructure project repositories. I need to add a dependency resolution project as a reference in my mvc application as this is the starting point ... but the problem is to register the controllers in this separate application. I need the mvc link in the dependency resolution project itself ... but such a thing is not possible because it will cause a circular link.

How to solve this problem? or what is the best way to manage dependency resolution? I do not want to register everything in Global.asax

+3
source share
2 answers

Get the latest version from the source tab at Munq.Codeplex.com. This version has improved views, and this is the version that I am most familiar with, and I wrote it.

To prevent circular references for registration, create a class project that includes reversals to Munq.Interfaces and the interfaces and implementations that you want to register.

, IMunqConfig. void RegisterIn ( IIocContainer). .

public class MyRegistration : IMuncConfig
{

    public void RegisterIn(IIocContainer container)
    {

        container.Register<IMyInterface>(c => new MyImplementation());

        //       OR

        container.Register<IMyInterface, MyImplementation>();

       // Repeat as required for each thing to register
    }
}

global.asax

protected void Application_Start()
{
    IocContainer = new Container();
    Munq.COnfigurationLoader.FindAndRegisterDependencies(container);

    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);
}

bin DLL, , IMunqConfig, RegisterIn. dll bin :)

+3

, mvc .

MVC- , . MVC "" , .

, , , DI. DI-, , DI .

(, ) (, MVC).

0

Source: https://habr.com/ru/post/1770252/


All Articles