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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
swegele opened this issue May 13, 2024 · 1 comment · Fixed by #3933
Assignees

Comments

@swegele
Copy link
Contributor

swegele commented May 13, 2024

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>();
swegele added a commit to swegele/csla that referenced this issue May 13, 2024
…tes which will stop ASPNet from including StateController (and it's CTOR services) in service registration; implementing a no-op session manager when inmemory app context manager is used.
rockfordlhotka added a commit that referenced this issue May 13, 2024
#3931)

* #3930 - Fix for v8.x branch removing api controller attributes which will stop ASPNet from including StateController (and it's CTOR services) in service registration;  implementing a no-op session manager when inmemory app context manager is used.

* Fix file header info

---------

Co-authored-by: Rockford Lhotka <[email protected]>
rockfordlhotka added a commit that referenced this issue May 13, 2024
swegele added a commit to swegele/csla that referenced this issue May 13, 2024
…tes which stops ASPNet from including StateController (and it's CTOR services) in service registration; implementing a no-op session manager when inmemory app context manager is used.
swegele added a commit to swegele/csla that referenced this issue May 13, 2024
StefanOssendorf added a commit that referenced this issue May 13, 2024
#3933)

* #3930 - Fix for main branch removing api controller attributes which stops ASPNet from including StateController (and it's CTOR services) in service registration; implementing a no-op session manager when inmemory app context manager is used.

* switching NotImplemented to NotSupported exceptions...good idea stefan;

* fixes from review;

* missed one;

---------

Co-authored-by: Stefan Ossendorf <[email protected]>
StefanOssendorf pushed a commit that referenced this issue May 13, 2024
rockfordlhotka added a commit that referenced this issue May 13, 2024
Co-authored-by: Stefan Ossendorf <[email protected]>
rockfordlhotka added a commit that referenced this issue May 13, 2024
* #3930 Update version to 8.1.2

* #3935 if SyncContextWithServer is false, properly initialize session

* #3929 Update version numbers to 8.2.0

* #3929 Update version numbers to 8.2.0
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants