Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Server App, using Scoped Service in class library without DI

$
0
0

My Blazor Server Project consists of 2 projects:

a) BlazorApp
Blazor components

b) Class Library (DAL)
Class 1
Class 2
SessionService class

The class library is generated using LLBLGEN. It is the layer for my database access.I cannot modify the constructor (e.g., to pass the service as a parameter). However, I can add my own classes here. My SessionService class is one such custom class. It stores information about the session, such as usernames, handles authentication, etc.

In Program.cs of my Blazor App, I register a scoped service like this:

builder.Services.AddScoped<SessionService>();

Within the Blazor app, I can use this service via Dependency Injection.

However, I need this scoped service within a class of the Class Library DAL, specifically in an event. Therefore, I cannot change the constructor or modify the method call to pass a parameter.

How can I achieve this?How can I access the service from the BlazorApp within the class library?I've tried using static classes/variables, but in a multi-user environment, that's probably not a good idea (even if it works locally in my development environment).


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>