Created
July 19, 2021 12:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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