Can't get dependency from container
See original GitHub issueHere is a demo repository https://gitlab.com/ittennull/bolero_di_issue/ First commit is the standard template as is, second commit adds an interface, registers it and tries to inject it:
type ISomething =
abstract member Foo: unit -> unit
type Something() =
interface ISomething with
member _.Foo() = ()
type MyApp() =
inherit ProgramComponent<Model, Message>()
[<Inject>]
member val Something = Unchecked.defaultof<ISomething> with get,set
let Main args =
let builder = WebAssemblyHostBuilder.CreateDefault(args)
builder.Services.AddSingleton<ISomething, Something>() |> ignore
...
I get " An unhandled exception was thrown by the application. System.InvalidOperationException: Cannot provide a value for property ‘Something’ on type ‘BoleroHostedApplication1.Client.Main+MyApp’. There is no registered service of type ‘BoleroHostedApplication1.Client.Main+ISomething’"
I tried the same thing with blazor wasm project in C# - worked fine
Any ideas?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Docker container can't find an installed node dependency
When I start up my docker container it can't find one of my installed dependencies. I've tried removing my build + node_modules folder, ......
Read more >ContainerDependency - Amazon Elastic Container Service
A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed. Your Amazon ECS ......
Read more >Throw/Exit when dependency can't be resolved · Issue #60
The problem is simple, I think that when dependency can't be satisfied (either it doesn't exist or one of its own dependencies wasn't...
Read more >Dependency injection in ASP.NET Core
Learn how ASP.NET Core implements dependency injection and how to use it.
Read more >Top 5 TypeScript dependency injection containers
Cover the top five containers for dependency injection in TypeScript, including Typed Inject, InversifyJS, TypeDI, TSyringe, and NestJS.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is indeed with prerendering. During prerendering, the client application’s
main
function isn’t called. Instead, the dependency injection is done using aspnetcore’s container. So any dependencies you need must also be injected in the server-sideConfigureServices
.If you don’t want prerendering, then you can do
.AddBoleroHost(prerendering = false)
inConfigureServices
. If you want it, then to avoid code duplication, you can write a function that injects everything you need and call it from both the client and the server: https://gitlab.com/Tarmil/bolero_di_issue/-/commit/22f0200b807a09ac56a81af80717518f8d8b44d0Oh, I didn’t know that thing about prerendering, I always thought it’s an optimization and didn’t care about it. Yes, it works now, thanks a lot!