Hi,
I’ve a solution in .NET 9 and c#. The solution has 3 sub-projects. One for the Domain layer, one for the BusinessLogic layer and one for the UI, which is a mixed Razor pages + blazor app. Both Domain and BusinessLogic project register their own services into the standard asp.net core IServicesCollection they get from the UI project.
I would like to add an alternative UI (a web desktop application) to this solution using Wisej.net 4.0.3.
I’ve followed the “Alternative IServiceProvider” part of the documentation and registered the Microsoft’s IServiceProvider with Wisej.NET.
I have some services registered in the Domain and/or business logic projects with Scoped lifetime.
When any of these service implementations are requested (either constructor or property injection or through the Application.Services.GetService<T>() method) in the Wisej.NET project, it gives a new instance for all the times. It seems DI does not care if i registered them with Scoped lifetime, it treats them as Transient.
In the razor pages/blazor project DI works correctly and handles scoped services well.
Am I miss anything to configure in the Wisej.net project?
Could you please show us the mapping between the service lifetime in Wisej.Net and in asp.net core?
How do I register a service with IServiceCollection if I want it to have a “Session” lifetime?
Any help of suggestions would be appreciated!
Thanks in advance,
Csaba
Microsoft DI only supports scoped, transient and singleton. There is no concept or support for sessions. Scoped means that you get a new service instance for each http request through the aspnet core razor middleware.
Wisej.NET service container instead supports session, transient, shared (singleton) and thread (kind of similar to scoped).
Since there are no http requests in Wisej.NET, being a fully ajax system and not using the page routers, postbacks, etc there is no concept of “sccoped”. If you want to share a service instance use a singleton.
Or use the Wisej.NET service container which works properly for the wisej application with the correct lifetime.
Please login first to submit.
