Composition root in an ASP.NET MVC DDD application

I am currently reading "Injecting Dependencies in .NET" by Mark Seeman. And I am wondering what would be the best way to build an ASP.NET MVC DDD application.

In a simplified scenario, the general rule would be to have a domain model that would be the core of the application, and would not have any dependencies on the data level or presentation. It will reveal certain interfaces that will use Presentation (hence the dependency) and Data Layer (hence the dependency). So everything is good and clear.

Dependencies in DDD app

, . ASP.NET MVC global.asax(http://blog.ploeh.dk/2011/07/28/CompositionRoot). , .

Composition Root in DDD app

, ( VS). , .

? , MVC .

UPDATE

, , : DAL → BLL < - GUI + . DI-? . , , , , .

, - . , DI ( ), , .

, , , , , .

+5
4

, .

, . , . , - .

, , , .

, . , :

public class CompositionRoot : IContainerModule
{
    public void Register(IContainerRegistrar registrar)
    {
        registrar.RegisterType<ISomeType, SomeType>();
    }
}

dll:

registrar.RegisterModules(Lifetime.Scoped, 
                          Environment.CurrentDirectory, 
                          "myproject.*.dll");

( RegisterType .. , [Component]).

https://github.com/jgauffin/griffin.container

+3

IoC .

, , , , .

():

// In data access assembly
namespace MyProject.DataAccessLayer
{
    internal class MyRepository : IMyRepository
    {
        // ...
    }

    public class DataAccessModule : IModule
    {
        void Configure(container)
        {
            container.ForInterface<IMyRepository>()
                     .UseType<MyReposutiry>()
                     .Singleton();
        }
    }
}

// In presentation layer assembly
namespace MyWebApp
{
    void Booptstrap()
    {
        var iocContainer = /* ... */

        iocContainer.AddModule(new RepositoryModule());
    }
}

, MyRepository . .

, IoC , .

+2

HTTP, ASP.NET WebAPI. ASP.NET MVC API. , . API , MVC. , .

, , , . , , . , , .

+1

, , eulerfx ( , ). , . , - api, , , webcontroller ( -) .

Now I have created several solutions using the methods described in the Injection Dependency in .NET book, and I can say that using the methods described in it certainly meant better quality, loosely coupled code.

Good luck

0
source

All Articles