Tôi đang cố gắng để đưa một phụ thuộc vào bộ điều khiển MVC của tôi như thế nàyUnity Khung IoC với constructor mặc định
private static void RegisterContainer(IUnityContainer container)
{
container
.RegisterType<IUserService, UserService>()
.RegisterType<IFacebookService, FacebookService>();
}
Lớp UserService có một constructor như thế này ...
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;
}
Trường hợp ngoại lệ Tôi đang nhận được như sau ...
Loại hiện tại, Repositories.IUserRepository, là một giao diện và không thể được xây dựng . Bạn có thiếu kiểu ánh xạ không?
Có vẻ như nó đang cố gắng đưa một nhà xây dựng vào dịch vụ, nhưng mặc định sẽ đủ? Tại sao nó không được ánh xạ tới hàm tạo parameterless?
'Repository' và' this.FacebookService' là gì? – SwDevMan81