I'm trying to inject a dependency to my MVC controllers like this
private static void RegisterContainer(IUnityContainer container)
{
container
.RegisterType<IUserService, UserService>()
.RegisterType<IFacebookService, FacebookService>();
}
The UserService class has a constructor like this...
public UserService(): this(new UserRepository(), new FacebookService())
{
//this a parameterless constructor... why doesnt it get picked up by unity?
}
public UserService(IUserRepository repository, IFacebookService facebook_service)
{
Repository=repository;
this.FacebookService=facebook_service;
}
The exception I am getting is the following...
The current type, Repositories.IUserRepository, is an interface and cannot be constructed. Are you missing a type mapping?
It looks like it's trying to inject a constructor into the service, but the default would suffice? Why is it not mapping to the parameterless constructor?
Repository
andthis.FacebookService
? – Vilipend