Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.31k stars 267 forks source link

Dependency Injection Issues when adding Azure SignalR service #502

Open paburgos opened 2 years ago

paburgos commented 2 years ago

Hi,

When using Blazor Server Side and configuring the Azure SignalR Service looks like services.AddMultiTenant conflicts with it.

To enable Azure SignalR is simple:

install the nuget package. Then addig this to startup.cs: services.AddSignalR().AddAzureSignalR();

In launchSettings.json adding this variable: "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.Azure.SignalR

Then it just matters to add SignalR connection string in the appsettings.

This is how the TenantInfo is registered: services.AddMultiTenant<MyTenantInfo>().WithConfigurationStore().WithHostStrategy();

The error I am getting is:

Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Cannot provide a value for property 'Tenant' on type 'Project1.Pages.Index'. There is no registered service of type 'Project1.Data.Multitenant.MyTenantInfo'.

System.InvalidOperationException: Cannot provide a value for property 'Tenant' on type 'Project1.Pages.Index'. There is no registered service of type 'Project1Data.Multitenant.MyTenantInfo'.

As soon as I remove all SignalR references, MultiTenant works back again.

What I might be doing wrong?

AndrewTriesToCode commented 2 years ago

hi @paburgos I'm not a Blazor expert but I suspect this has to do with how Blazor handles scoped DI. Here is how the services are registered for Finbuckle.MultiTenant.

Here are the Blazor DI docs

I'm going to take a closer look and try to figure out what's happening -- do you have a repo with the issue you can share with me?

paburgos commented 2 years ago

Hi @AndrewTriesToCode

I just uploaded this repo: https://github.com/paburgos/SignalRFinbuckleIssue

it should work as is, and show you "My Tenant Name" from Index

To reproduce the error, you can uncomment all sections related to SignalR: https://github.com/paburgos/Issues/blob/main/SignalRFinbuckleIssue/appsettings.json https://github.com/paburgos/Issues/blob/main/SignalRFinbuckleIssue/Properties/launchSettings.json

And enable, this //builder.Services.AddSignalR().AddAzureSignalR(); in https://github.com/paburgos/Issues/blob/main/SignalRFinbuckleIssue/Program.cs

Hope this helps, and thank you for taking the time and the prompt response!