0

using Web API 2 with Unity IOC. I'm trying to figure out where can I register the types used across the whole solution.

In Asp.Net Web API all types registering is done in a class, called UnityConfig

public class UnityConfig
{
    public static void Register(HttpConfiguration config)
    {
        var container= new UnityContainer();

        container.RegisterType<IUsersService, UsersService>(); // BLL type
        container.RegisterType<IRolesService, RolesService>(); // BLL type
        container.RegisterType<IUnitOfWork, UnitOfWork>(); // DAL type

        GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
    }
}

which is then configured when the application first starts by the Global.asax.

PROBLEM IS - as long as its just the BLL services, everything is fine, application is supposed to be referencing BLL anyway.

but when DataAccessLayer repositories, which I also want to inject, come into play, this forces my main project, the "application layer" to have reference to the DAL project. a dependency which I don't want.

Where is my failure in the understanding of the concept ?

SHR
  • 7,940
  • 9
  • 38
  • 57
  • 1
    I answered siimilar question a while back https://stackoverflow.com/questions/40401900/bootstrapping-unity-composition-root-location/40403875#40403875 – Marcus Höglund Jul 09 '18 at 18:56
  • Add the reference to configure Unity, but do not directly code against the DAL in the WebAPI application. – Jasen Jul 09 '18 at 20:18

0 Answers0