Closed dazinator closed 6 years ago
I have made a sweeping refactoring to the structure of projects, in order to seperate out asp.net core
in my feature branch: https://github.com/dazinator/Dotnettency/tree/feature/seperate-http to allow dotnettency
to be consumed in non asp.net core scenarios (like xamarin) and not bring in any asp.net core dependencies.
This now means there are some changes to the packages you have to pull in for asp.net core
applications.
Dotnettency.HostingEnvironment
--> Dotnettency.AspNetCore.HostingEnvironment
Dotnettency.MiddlewarePipeline
--> Dotnettency.AspNetCore.MiddlewarePipeline
Dotnettency.Container
--> Dotnettency.AspNetCore.Container
Dotnettency.Modules
--> Dotnettency.AspNetCore.Modules
Some of the previous packages like Dotnettency.Container
still exists, but they have had all asp.net core stuff stripped form them so they can be used in non asp.net core scenarios like xamarin app.
For an asp.net core application, when you switch to the new packages, it should also pull in a new package automatically as a dependency: Dotnettency.AspNetCore
.
This will now add a new extension method: .AddDefaultHttpServices()
which you should call within startup.cs:
var serviceProvider = services.AddMultiTenancy<Tenant>((options) =>
{
options
.AddDefaultHttpServices()
All that method does is register a couple of default services that are only applicable for asp.net core scenario:
builder.Services.AddSingleton<ITenantDistinguisherFactory<TTenant>, RequestAuthorityTenantDistinguisherFactory<TTenant>>();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
These were previously registered for you automatically, however now dotnettency doesn't make any assumptions that its operating within a asp.net core website environment. The RequestAuthorityTenantDistinguisherFactory
is just a default implementation that distinguishes tenants based on the authority of the request.
If you are already registering your own implementations of these services yourself then you don't need to call this method just continue to register your own.
Lastly if using PerTenantContainers
you must also register the asp.net core specific services by calling .AddPerRequestContainerServices
)
containerBuilder.WithStructureMap((tenant, tenantServices) =>
{
// lots of stuff
})
.AddPerRequestContainerMiddlewareServices(); // registers services needed for asp.net core middleware to make per request tenant containers. I.e you need to call this if you are calling `UsePerTenantContainers()`
This was to allow xamarin apps (that dont need per request containers!) to set up tenant containers in the same way, and then asp.net core apps that use the per tenant container middleware must optionally call this additional registration.
These changes will be released with major version 2.0.0
packages: https://www.nuget.org/packages/Dotnettency/2.0.0-seperate-http.1
I have bumped the major version to signify breaking change.
I have an xamarin android app that can be used by multiple users. Each users that signs into the app should be considered a tenant, as I need to partition the database based on tenant id (i.e in this case user id).
I am going to investigate removing any http / web dependencies from
Dotnettency
core library, and then perhaps I can use dotnettency with my xamarin app too.