我有一个简单的界面,如下所示:
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());