I use Unity with Unity.MVC5. The class that registers the types and the dependency resolver is as below:
public static class UnityConfig
{
public static void RegisterComponents()
{
var container = new UnityContainer();
container
.RegisterType<ILogger, Nlogger>()
.RegisterType<IDataAccessLayer, SqlDataAccessLayer>()
.RegisterType<IEventBusiness, EventBusiness>();
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
}
And here is my Global.asax code:
void Application_Start(object sender, EventArgs e)
{
UnityConfig.RegisterComponents();
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
In one of my controllers I have a property like this:
[Dependency]
public IEventBusiness EventBusiness { get; set; }
I expect that this property be set automatically by Unity but it's always null. Can someone help me to figure out what I am doing wrong?
In the Open Unity project, navigate to Assets dropdown menu and choose Play services resolver > Android Resolve. Select the Resolve or Force Resolve.
The dependencyResolutionManagement repositories block accepts the same notations as in a project, which includes Maven or Ivy repositories, with or without credentials, etc. By default, repositories declared by a project will override whatever is declared in settings.
You can find the project manifest file, called manifest. json , in the Packages folder under the root folder of your Unity project.
Thanks for your help guys. I removed Unity.MVC5 and installed Unity plus Unity.Bootstrapper instead. Now everything works fine. I followed this article to resolve the issue: http://msdn.microsoft.com/en-us/library/dn178463(v=pandp.30).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With