Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AspNetCoreFacility Component Register Issue #478

Closed
fulinlin opened this issue Mar 19, 2019 · 0 comments · Fixed by #489
Closed

AspNetCoreFacility Component Register Issue #478

fulinlin opened this issue Mar 19, 2019 · 0 comments · Fixed by #489

Comments

@fulinlin
Copy link

fulinlin commented Mar 19, 2019

In a .Net Core 2.2 WebAPI project, An exception is thrown when registering a component with DependsOn after calling the AddWindsor method.

Used:

.Net Core 2.2.0
Castle.Windsor 5.0.0
Castle.Facilities.AspNetCore 5.0.0
Here you can find the code to reproduce the issue.

// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
    // Setup component model contributors for making windsor services available to IServiceProvider
    Container.AddFacility<AspNetCoreFacility>(f => f.CrossWiresInto(services));
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
	
    // Castle Windsor integration, controllers, tag helpers and view components, this should always come after RegisterApplicationComponents
    var serviceProvider = services.AddWindsor(Container,
        opts => opts.UseEntryAssembly(typeof(ValuesController).Assembly), // <- Recommended
        () => services.BuildServiceProvider(validateScopes: false)); // <- Optional
		
    // An exception is thrown when registering a component with DependsOn after calling the AddWindsor method.
    Container.Register(
        Component.For<IDemo>().ImplementedBy<Demo1>(),
        Component.For<IDemo>().ImplementedBy<Demo2>(),
        Component.For<IDemoService>().ImplementedBy<DemoService>().DependsOn(Dependency.OnComponent<IDemo, Demo2>()));

    return serviceProvider;
}

Exception Message:
Object reference not set to an instance of an object.
StackTrace:
at Castle.Facilities.AspNetCore.Resolvers.GenericTypeExtensions.MatchesType(Type type, Type otherType)
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.<>c__DisplayClass15_0.b__0(ISubDependencyResolver s)
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
at Castle.MicroKernel.Handlers.AbstractHandler.HasValidComponentFromResolver(DependencyModel dependency)
at Castle.MicroKernel.Handlers.AbstractHandler.AddResolvableDependency(DependencyModel dependency)
at Castle.MicroKernel.Handlers.AbstractHandler.AddDependency(DependencyModel dependency)
at Castle.MicroKernel.Handlers.AbstractHandler.InitDependencies()
at Castle.MicroKernel.Handlers.AbstractHandler.Init(IKernelInternal kernel)
at Castle.MicroKernel.Handlers.DefaultHandlerFactory.Create(ComponentModel model)
at Castle.MicroKernel.DefaultKernel.AddCustomComponent(ComponentModel model)
at Castle.MicroKernel.Registration.ComponentRegistration`1.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel)
at Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations)
at Castle.Windsor.WindsorContainer.Register(IRegistration[] registrations)
at CastleWindsorTest.Startup.ConfigureServices(IServiceCollection services) in Startup.cs:line 41

@fulinlin fulinlin changed the title Castle.Facilities.AspNetCore Register issue AspNetCoreFacility Component Register Issue Mar 19, 2019
dariuslf pushed a commit to dariuslf/Windsor that referenced this issue Jun 13, 2019
dariuslf added a commit to dariuslf/Windsor that referenced this issue Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant