-
Notifications
You must be signed in to change notification settings - Fork 36
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
IoC example #113
Comments
I'll try to summarize the example code more or less in the order I would code them. So in addition to your service you need a "startup service". Instead of a normal service proxy. And then you use this instance to spawn new instances using IoC. This is where you would call your usual extension methods like in asp.net Your service (in the example, https://github.com/Tewr/BlazorWorker/blob/main/src/BlazorWorker.Demo.IoCExample/MyIocService.cs), should just declare its dependencies as usual with finally, the setup from your service proxy, the most simple is the one-liner described in https://github.com/Tewr/BlazorWorker/blob/main/src/BlazorWorker.Demo/SharedPages/Pages/IoCExamplePage.razor :
you can do this in two steps like shown in the example if you have several different service proxys to instantiate (it will be more efficient to reuse a startup service), or if you want to dispose services after each use. Does that help you? |
I am trying to use the worker service to delegate a few long running tasks in a background thread after a http response is returned, however i have a major issue with initialization.
What i am trying to do is create a background worker of a service type and that service has multiple dependencies that would usually be retrieved from the IServiceProvider. However i cannot understand how to inject the IServiceProvider in any way using the usual dependency injection container.
The text was updated successfully, but these errors were encountered: