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

Need to call UseServiceProviderFactory #83

Open
sam-wheat opened this issue May 6, 2023 · 3 comments
Open

Need to call UseServiceProviderFactory #83

sam-wheat opened this issue May 6, 2023 · 3 comments
Labels
All OS enhancement New feature or request

Comments

@sam-wheat
Copy link

PhotinoBlazorAppBuilder does not implement IHostBuilder so I can not use this. Is there a workaround?

I need to use Autofac service provider:

builder.UseServiceProviderFactory(new AutofacServiceProviderFactory());

@MikeYeager MikeYeager added enhancement New feature or request All OS labels May 11, 2023
@MikeYeager
Copy link
Collaborator

@sam-wheat Photino.Blazor is built on the Microsoft.NETCore.App framework. In order to do what you're asking, we'd have to switch to the Microsoft.AspNETCore.App framework which would bloat the project a bit. While this may be a reasonable step to take, it's not a minor change. You can use the default dependency injection, but using Autofac won't be supported until this change is made, tested and published, which likely won't happen soon unless you or someone in the community picks this up.

@sam-wheat
Copy link
Author

I actually did look at implementing IHostBuilder - it is something I'd like to do but unfortunately it is yet another distraction from my main project which is long overdue.

We'd have to switch to the Microsoft.AspNETCore.App framework

You should be able to just add a reference to Microsoft.Extensions.Hosting, correct?

The workaround is pretty simple but not something I would want to do in a large app:

// Program.cs

var builder = PhotinoBlazorAppBuilder.CreateDefault(args);
ContainerBuilder containerBuilder = new();
// add services to containerBuilder and dotnet container here
containerBuilder.Populate(builder.Services);
IContainer container = containerBuilder.Build();
builder.Services.AddSingleton(typeof(IContainer), container);
app = builder.Build();


// Your page

@code {

	[Inject] IContainer container { get; set; }
	

	protected override async Task OnInitializedAsync()
	{
		await base.OnInitializedAsync();
		ILifetimeScope scope = container.BeginLifetimeScope();
		myService = scope.Resolve<IMyService>();
	}

@philippjbauer
Copy link
Member

This change has been proposed in the following PR. We still need to test it ...

#122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
All OS enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants