volosoft / castle-windsor-ms-adapter

Castle Windsor ASP.NET Core / Microsoft.Extensions.DependencyInjection Adapter
https://www.nuget.org/packages/Castle.Windsor.MsDependencyInjection
MIT License
85 stars 29 forks source link

Usage with .net core 3.0 #35

Closed robertmircea closed 3 years ago

robertmircea commented 4 years ago

How can I use this library with .net core 3.0? Is there any sample code on how to configure host and asp.net core mvc?

ismcagdas commented 4 years ago

@robertmircea we haven't tried it with .NET Core 3.0 preview packages but it should work since this is .NET Standard.

gokhanabatay commented 4 years ago

When you use UseServiceProviderFactory() method this package already supports .net core 3.0 latest version.

public static class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateWebHostBuilder(string[] args)
        {
            LoggingFacility.AddApplicationTag(typeof(Program).Assembly.GetName().Name);
            LoggingFacility.AddEnvironmentTag();

            return Host.CreateDefaultBuilder(args)
                    .UseServiceProviderFactory(new WindsorServiceProviderFactory())
                    .ConfigureWebHostDefaults(builder =>
                    {
                        builder.UseStartup<Startup>()
                        .UseAppMetrics()
                        .UseKestrel(options => options.AddServerHeader = false)
                        .UseLogFactory()
                        .UseIIS()
                        .UseIISIntegration();
                    });
        }
    }

In Startup.cs void ConfigureServices(IServiceCollection services) method register your windsor container instance with services.AddSingleton(IocFacility.Container);

chrisheil commented 4 years ago

@gokhanabatay Where is the "locFacility.Container" coming from in the Startup.cs void ConfigureServices method from your example? Is there a working demo anywhere I could reference?

gokhanabatay commented 4 years ago

Hi @chrisheil

@gokhanabatay Where is the "locFacility.Container" coming from in the Startup.cs void ConfigureServices method from your example? Is there a working demo anywhere I could reference?

IocFacility.Container is a public static singleton WindsorContainer instance, key point is use of UseServiceProviderFactory(new in .net core 3.0) in Program.cs. All u need is above Program.cs and Startup.cs register singleton instance of WindsorContainer as sigleton to IServiceCollection.

demirmusa commented 4 years ago

Hi @gokhanabatay, I also can not find IocFacility.Container reference on startup.

I tried on https://github.com/aspnetboilerplate/module-zero-core-template with

services.AddSingleton(IocManager.Instance.IocContainer);//its IWindsorContainer reference

and problem still exists. What is your project?

vdurante commented 3 years ago

@demirmusa were you able to make it work?

maliming commented 3 years ago

@vdurante see https://github.com/aspnetboilerplate/aspnetboilerplate/pull/5331