1

Structuremap中以下内容的等价物是什么

kernel.Bind<IQueryDispatcher>().To<QueryDispatcher>();
kernel.Bind<ICommandDispatcher>().To<CommandDispatcher>();

kernel.Bind(x => x
  .FromAssembliesMatching("MyApp.dll")
  .SelectAllClasses().InheritedFrom(typeof(IQueryHandler<,>))
  .BindAllInterfaces());

kernel.Bind(x => x
  .FromAssembliesMatching("MyApp.dll")
  .SelectAllClasses().InheritedFrom(typeof(ICommandHandler<>))
  .BindAllInterfaces());

-阿伦

4

1 回答 1

0

这应该做的工作:

public class MyAppRegistry : Registry
{
    public MyAppRegistry()
    {
        this.For<IQueryDispatcher>().Use<QueryDispatcher>();
        this.For<ICommandDispatcher>().Use<CommandDispatcher>();
        Scan(scan =>
        {
            scan.AssembliesFromApplicationBaseDirectory(a => a.FullName.StartsWith("MyApp"));
            scan.WithDefaultConventions();
            scan.AddAllTypesOf(typeof(IQueryHandler<,>));
            scan.AddAllTypesOf(typeof(ICommandHandler<>));
        });
    }
}
于 2015-08-15T00:45:14.463 回答