-
Hi, I am trying to use a common session interface depending on the situation in my services. In some cases I would like to use stateless session in Asp.Net Core. For example: Program.cs builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<ISessionFactory>(s => s.CreateSessionFactory(ConnectionString))
builder.Services.AddScoped<????>(s =>
{
if (s.GetRequiredService<IHttpContextAccessor>().HttpContext.Request.Method == "GET")
return s.GetRequiredService<ISessionFactory>().OpenStatelessSession();
else
return s.GetRequiredService<ISessionFactory>().OpenSession();
}); Just to clarify one thing. There are methods in some services where an entity is being fetched from the database and then used in both GET and POST situations. So that service does not know which session to use. It can be persisted or not. What interface I can use to utilize the session instance which later can be used in NH queries? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As you can see on the interfaces, there's no commonality, except IDisposable. You could create wrapper classes, with a common interface. |
Beta Was this translation helpful? Give feedback.
As you can see on the interfaces, there's no commonality, except IDisposable.
You could create wrapper classes, with a common interface.