我刚开始使用Unity Container,我的注册看起来像这样:
static void UnityRegister() { _container = new UnityContainer(); _container.RegisterType<IBook,Book>(); _container.RegisterType<IBookRepository,BookRepository>("Book"); _container.RegisterType<IBookService,BookService>(); _container.RegisterType<IBookRepository,DatabaseRepository>("Database"); }
现在当我尝试解决这个问题:
var service = _container.Resolve<IBookService>("Database");
我收到以下错误:
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
谁能指出我做错了什么?