0

I've got an Dot.Net 7 Blazor WASM app running with Duende configured for authentication.

I've also got an Orleans silo running in the server side and I wish to deactivate a grain when the user logs out.

I can wire up to the logged out event using OpenIdConnect e.g:

.AddOpenIdConnect("oidc", options =>
    {
        ...

        options.Events = new OpenIdConnectEvents
        {           
            OnSignedOutCallbackRedirect = c => Task.FromResult(0),
            OnRemoteSignOut = c => Task.FromResult(0),
            OnRedirectToIdentityProviderForSignOut = c => Task.FromResult(0),
        };
    });

But I need to be able to inject in the IGrainFactory whenever this event is raised to be able to speak to the grain.

Orleans aside as I don't think that's important to my issue (I could be DIing anything), how can I access an object in this event that should be injected in?

Progman
  • 16,827
  • 6
  • 33
  • 48
ADringer
  • 2,614
  • 36
  • 63
  • Does this answer your question? [How to inject services in an AddOpenIdConnect event (OnTokenValidated)?](https://stackoverflow.com/questions/68547805/how-to-inject-services-in-an-addopenidconnect-event-ontokenvalidated) – Odrai Jun 01 '23 at 20:19

1 Answers1

0

Something like this should work:

builder.Services.AddOptions<OpenIdConnectOptions>("oidc")
                .Configure<IGrainFactory>((options, grainFactory) =>
                {
                    options.Events = new OpenIdConnectEvents()
                    {

                    };
                });

Calling AddOpenIdConnect does the moral equivalent. AddOptions<T>(..).Configure<T0..TN> lets you inject dependencies while having access to the options.

davidfowl
  • 37,120
  • 7
  • 93
  • 103