DEV Community

mshakurov
mshakurov

Posted on

Blazor server. Scoped Service created twice.

If Razor Component1 injecting Scoped Service1 is inserted outside the @Body of the LayoutComponent, then Service1 is created 2 times. Even if you insert 100 such components outside the @Body, two services will be created nevertheless. If Component1, or 100 such components is inserted inside another Razor Component2 inside the @Body, then Service1 is created once. What is the problem and how to work around it if I need to display Service1's data on the main View without having two instntiations of the Service1?

Top comments (0)