Skip to content

Commit

Permalink
Merge pull request #46 from baodden/wrap-addservices-in-installer
Browse files Browse the repository at this point in the history
Wrap AddServices in an IWindsorInstaller to reduce registration/startup time
  • Loading branch information
ismcagdas authored Dec 26, 2023
2 parents db284d5 + a19eeda commit 641252c
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceDescriptor = Microsoft.Extensions.DependencyInjection.ServiceDescriptor;

Expand All @@ -26,6 +27,11 @@ public static IServiceProvider CreateServiceProvider(IWindsorContainer container
/// Used to add services to an existing container, without creating a <see cref="IServiceProvider"/>.
/// </summary>
public static void AddServices(this IWindsorContainer container, IServiceCollection services)
{
container.Install(new ServiceCollectionInstaller(services));
}

internal static void AddServicesInternal(this IWindsorContainer container, IServiceCollection services)
{
AddBaseServices(container);
AddSubResolvers(container);
Expand Down Expand Up @@ -173,4 +179,19 @@ private static ComponentRegistration<object> ConfigureLifecycle(this ComponentRe
return registrationBuilder;
}
}

internal sealed class ServiceCollectionInstaller : IWindsorInstaller
{
private readonly IServiceCollection _services;

public ServiceCollectionInstaller(IServiceCollection services)
{
_services = services;
}

public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddServicesInternal(_services);
}
}
}

0 comments on commit 641252c

Please sign in to comment.