I just starting with Unity Container and my registration looks like this:
static void UnityRegister()
{
_container = new UnityContainer();
_container.RegisterType<IBook, Book>();
_container.RegisterType<IBookRepository, BookRepository>("Book");
_container.RegisterType<IBookService, BookService>();
_container.RegisterType<IBookRepository, DatabaseRepository>("Database");
}
Now when I try to resolve doing this:
var service = _container.Resolve<IBookService>("Database");
I get error below:
Resolution of the dependency failed, type = "UnityConsoleEx.IBookService", name = "Database". Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, UnityConsoleEx.IBookService, is an interface and cannot be constructed. Are you missing a type mapping?
At the time of the exception, the container was:
Resolving UnityConsoleEx.IBookService,Database
Can anyone point what I am doing wrong?