Per-tenant options not set for a class
See original GitHub issueHello,
I’ve been implementing a custom MultiTenantStore, since i am using a nosql database to store tenants. Now that part works as it seems, since i get the TenantInfo when i get the MultiTenantContext. Now the part where i setup per-tenant options for a class, , called TenantOptions, and has one property “ConnectionString”, which i use to inject into my MongoContext to connect to the tenant-specific database, is not working apparently.
What i am doing is:
services.AddMultiTenant() //strategy ... //store .. //.WithPerTenantOptions<TenantOptions>((to, ti) => {to.ConnectionString = ti.ConnectionString})
Apparently whenever the TenantOptions instance is called by the MongoContext, the ConnectionString is null
.
I’m not sure if i am using the WithPerTenantOptions<TOptions>()
method correctly.
Please do point me what i am doing wrong. Many thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Hi @vlatkozmejkoski Can you post a sample of what your
TenantOptions
class looks like? Also isTenantOptions
registered for DI as a singleton, scoped, or transient?In theory, in your mongo db setup area you will inject
IOptions<TenantOptions>
,IOptionsSnaption<TenantOptions>
, orIOptionsMonitor<TenantOptions>
from which you get theTenantOptions
instance and it should pick up the tenant info.If you are only using
TenantOptions
to get the connection string you can skip a lot of this… just injectTenantInfo
into your mongo db setup area and use the connection string onTenantInfo
directly.Thanks for letting me know. I will take a look at how the library interacts with authorization policies and related requirements.