0

Attempting to learn to build a layered project from the ground up in MVC this weekend and dependency injection is taking its toll. My solution is built like so:

Web.UI | Service Interfaces | Service Implementations | and so on...

UnityConfig is in the App_Start like most tutorials suggest but when trying to resolve the interfaces with their implementations I can't because the UI project only references the interfaces. This is my first time trying to properly apply an architecture to a project that wasn't already built and tutorials seems to always suggest that you can reference both, which goes against basic patterns.

I can't seem to find a good tutorial on this that doesn't seem to either over simplify things with two classes in the same project or the extreme opposite.

Code looks like this:

Global.asax

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        UnityConfig.Initialise();
    }
}

UnityConfig

public static class UnityConfig
{
    private static IUnityContainer Initialise()
    {
        var container = new UnityContainer();

        container.RegisterType<ISystemUserService, SystemUserService>();

        return container;
    }
}
  • You *could* move the `UnityConfig` to a new project/assembly, reference that in the Web.UI project, and have all others that are necessary be referenced in the this new "IoC" project (or whatever you call it). Doing this should keep with your desire to stick to basic patterns. – R. Richards Jun 25 '17 at 14:47
  • @R.Richards Is it really that simple? That's embarrasing. Think it's time to have a break – user3112059 Jun 25 '17 at 14:53
  • Nothing to be embarrassed about! But, it is a good time for a break. :) – R. Richards Jun 25 '17 at 16:05

0 Answers0