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;
}
}