Skip to content

Instantly share code, notes, and snippets.

@jamie-tillman
Created July 19, 2021 12:06
Show Gist options
  • Save jamie-tillman/0ff425e34f613b2d9fa4ade26980e5eb to your computer and use it in GitHub Desktop.
Save jamie-tillman/0ff425e34f613b2d9fa4ade26980e5eb to your computer and use it in GitHub Desktop.
Example of using Castle Windsor and Castle.Windsor.MsDependencyInjection with DotNetCore HostBuilder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.MsDependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Scheduler
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory((builder) =>
new WindsorServiceProviderFactory())
.ConfigureContainer<WindsorContainer>(container =>
{
// Could register components here, like this
// container.Register(Component.For<IHostedService>()
// .ImplementedBy<Worker>()
// .LifestylePerThread());
})
.ConfigureServices((hostContext, services) =>
{
// Unsure if this is using the registered Windsor Container or not, at this point
services.AddHostedService<Worker>();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment