2015-08-14 62 views
1

的equivalant什么是Structuremap以下的什么是以下Ninject声明中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()); 

-Arun

回答

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<>)); 
     }); 
    } 
}