Skip to content

In 8.1.1 (prob in 9 too) - when ".UseInMemoryApplicationContextManager = true" you get "Unable to resolve service for type 'Csla.State.ISessionManager'" #3930

@swegele

Description

@swegele

First noticed by @russblair mentioned on discord channel
Confirmed by @swegele

Repro:
Blazor Server-Interactive Only project (no wasm or any refs to new .NET 8 state management stuff)
Config in blazor server program.cs

builder.Services.AddCsla(o => o
  .AddAspNetCore()
  .AddServerSideBlazor(bsco => bsco
    .UseInMemoryApplicationContextManager = true));

...

        app.UseEndpoints(delegate (IEndpointRouteBuilder endpoint)
        {
            endpoint.MapControllers();
        });

Csla config correctly skips making any reference or registration to any state management stuff. But none-the-less somehow .NET DI is looking for ISessionManager. We think that ASPNet is scanning the project (and it's dependencies) for controllers and it finds the [ApiController] attribute here:

Csla.AspNetCore.Blazor.State.StateController

  [ApiController]
  [Route("[controller]")]
  public class StateController(ApplicationContext applicationContext, ISessionManager sessionManager) : ControllerBase

WORKAROUND
I did a test workaround suggested by @TheCakeMonster making a no-op implementation for the ISessionManager interface and registered it. With this the DI error goes away and project runs as expected.

using Csla.State;

    public class NoOpSessionManager : ISessionManager
    {
        public Session GetCachedSession()
        { throw new NotImplementedException(); }
        public Session GetSession()
        { throw new NotImplementedException(); }
        public void PurgeSessions(TimeSpan expiration)
        { throw new NotImplementedException(); }
        public Task<Session> RetrieveSession()
        { throw new NotImplementedException(); }
        public Task SendSession()
        { throw new NotImplementedException(); }
        public void UpdateSession(Session newSession)
        { throw new NotImplementedException(); }
    }
...

builder.Services.AddSingleton<Csla.State.ISessionManager, NoOpSessionManager>();

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions