문제

i have the following interfaces injected in Castle Windsor. how do i do the same in Ninject?

container.Register(
    AllTypes.FromAssemblyNamed("Apps.Web")
        .BasedOn(typeof(ICommandHandler<>))
        .WithService.FirstInterface());

i've tried:

this.Bind(x => x.FromAssembliesMatching("Apps.Web.dll")
     .Select(y => y.Namespace.EndsWith("Handlers"))
     .BindSingleInterface());

but getting Object reference not set to an instance of an object error.

도움이 되었습니까?

해결책

You can use Ninject's convention binding extensons (install it from NuGet) to do this.

Something like the following should work

kernel.Bind(x => x.FromAssembliesMatching("Apps.Web")
    .SelectAllClasses()
    .InheritedFrom(typeof(ICommandHandler<>))
    .BindSingleInterface());

I'm not 100% sure about the FromAssembliesMatching pattern, but you should be able to tweak that to pick up your assembly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top