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

ASP.NET Core 6: WebApplicationBuilder Example? #607

Open
sianabanana opened this issue Feb 9, 2022 · 4 comments
Open

ASP.NET Core 6: WebApplicationBuilder Example? #607

sianabanana opened this issue Feb 9, 2022 · 4 comments

Comments

@sianabanana
Copy link

sianabanana commented Feb 9, 2022

Are there any examples of how to use Castle Windsor with the new .net 6 Core minimal style

This site has a autofac example
https://andrewlock.net/exploring-dotnet-6-part-10-new-dependency-injection-features-in-dotnet-6/

var builder = WebApplication.CreateBuilder(args);

// Call UseServiceProviderFactory on the Host sub property 
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());

// Call ConfigureContainer on the Host sub property 
builder.Host.ConfigureContainer<ContainerBuilder>(builder => 
{
    builder.RegisterModule(new MyApplicationModule());
});

var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

Is there a simmilar example for castle? i cant find a castle service provider factory for example.

Previously i was using the Castle.Windsor.MsDependencyInjection
WindsorRegistrationHelper.CreateServiceProvider(container, services);

@generik0
Copy link
Contributor

Yes, MS are irritating, changing this all the time. I will try to fix this up ASAP

@generik0
Copy link
Contributor

Wait, with the latest version, doesn't this work? builder.Host.UseServiceProviderFactory(new WindsorServiceProviderFactory());

@sianmace
Copy link

Yes, sorry for not replying but i eventually found the solution.
As you say

builder.Host.UseServiceProviderFactory(new WindsorServiceProviderFactory());

then i do

builder.Host.ConfigureContainer<WindsorContainer>((hostBuilderContext, container) =>
{
    container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));

etc.

Thanks for getting back to me

@sianmace
Copy link

It would probs be useful to add an example to the library to save other peoples pain.

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

3 participants