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

Castle.Windsor.Extensions.DependencyInjection - Existing Container is cleared of all registrations #605

Open
DamienLaw opened this issue Jan 4, 2022 · 1 comment

Comments

@DamienLaw
Copy link

DamienLaw commented Jan 4, 2022

public class Program
{
    public static async Task Main(string[] args)
    {
        var testClass = new TestClass();
        var container = new WindsorContainer();
        container.Register(Component.For<ITestClass>().Instance(testClass));

        await Host.CreateDefaultBuilder(args)
            .UseWindsorContainerServiceProvider(container) // <-- This will cause the container to be cleared as if it was a brand newly instantiated container.
            .RunAsync();
    }
}

This happens right after a subsystem is added to the container

protected virtual void AddSubSystemToContainer(IWindsorContainer container)
{
container.Kernel.AddSubSystem(
SubSystemConstants.NamingKey,
new SubSystems.DependencyInjectionNamingSubsystem()
);
}

Is this by design? Is there no way I could use the existing registrations prior to .UseWindsorContainerServiceProvider(container)?

Update:
I just realized in the XML Documentation that all registrations will be cleared. Didn't notice that before.

/// <summary>
/// Uses <see name="IWindsorContainer" /> as the DI container for the host
/// </summary>
/// <param name="hostBuilder">Host builder</param>
/// <param name = "container">Windsor Container to be used for registrations, please note, will be cleared of all existing registrations</param>
/// <returns>Host builder</returns>
public static IHostBuilder UseWindsorContainerServiceProvider(this IHostBuilder hostBuilder, IWindsorContainer container)
{
return hostBuilder.UseServiceProviderFactory<IWindsorContainer>(new WindsorServiceProviderFactory(container));
}

Is it possible to copy the registrations back over?

@ikkentim
Copy link
Contributor

Maybe this helps: #627 (comment)

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

No branches or pull requests

2 participants