我有一个简单的界面,如下所示:
public interface ICommandHandler<T>
{
void Handle(T command);
}
然后我有该接口的几个实现,这里是一个例子:
public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand>
{
private readonly IUserRepository _userRepository;
public RegisterUserCommandHandler(IUserRepository userRepository)
{
_userRepository = userRepository;
}
public void Handle(RegisterUserCommand command)
{
var user = new User(command.UserId, command.Password);
_userRepository.Add(user);
}
}
我无法ICommandHandler
像这样解决接口的正确实现:
var handler = _kernel.Get<ICommandHandler<T>>();
我的问题是:如何使用 Ninject 配置绑定?
更新 也许我想出了这个,这是我使用Ninject.Extensions.Conventions的解决方案
_kernel.Bind(x => x
.FromAssemblyContaining<ICommandInvoker>()
.SelectAllClasses().Excluding<IDocumentSession>()
.BindAllInterfaces());