Ticket T1002457
Visible to All Users

Dynamic Database Name XAF Blazor

created 4 years ago

Hi,

We are currently developing a xaf blazor multi tenant application following the example you have provided().

The database name seems to be hard coded and would want to find out if you can at lease provide a similar example where the databases are derived from another table or a function. This will be helpful and close to a real life scenario enough. We have wasted over a week trying to do this but it isn't working.

Please treat this as urgent as we are currently behind schedule in our project due to the above.

Kind regards.

Answers

created 4 years ago (modified 4 years ago)

Hi,

As a customer/xaf user maybe we can describe what we did here and we hope it helps.
First we created a addition xaf app called (MasterAdminXXX). In this app we have the following structure :

BO of MasterAdminXXX :

  • Tenant (name + connectionstring + XpCollection of Tenant Access + XpCollection of API access)
  • Access (Name + username --> email address in our case)
  • Tenant Access ( Tenant + Access + additional info proper to our env.)
  • Tenant Api access ( Name + API RSA token)

in Xaf app there is no connectionstring to the XAF db as we defined it on the fly. We manage to find the right CS based on the login so on the OnLoggingOn (DX example). For this we connect to the XAF app and request the CS by the tenantaccess:

C#
protected override void OnLoggingOn(LogonEventArgs args) { base.OnLoggingOn(args); try { IConfiguration configuration = ServiceProvider.GetRequiredService<IConfiguration>(); var adminCS = configuration.GetConnectionString("AdminConnectionString"); var AdminDal = XpoDefault.GetDataLayer(adminCS, DevExpress.Xpo.DB.AutoCreateOption.None); using (var baUow = new UnitOfWork(AdminDal)) { var username = ((AuthenticationStandardLogonParameters)args.LogonParameters).UserName; XAFAdminApp.Module.BO.TenantAccess tenantAccess = baUow.Query<XAFAdminApp.Module.BO.TenantAccess>() .Where(ta => ta.Access.UserAccess == username) .First(); if (tenantAccess != null) { ((XPObjectSpaceProvider)ObjectSpaceProviders[0]).SetDataStoreProvider(GetDataStoreProvider(tenantAccess.Tenant.ConnectionString, null)); } } } catch { throw new UserFriendlyException($"Unknown user name or password. Please check the data entered or call technical support."); } }

Then in the user table in the XAF app via controller we sync when a user is create and delete with MasterAdminXXX via the ObjectSpace_Committing + ObjectSpace_ObjectDeleting.

Please take it as and idea and not a solution.

BR
ISA

    Show previous comments (7)

      Thanks Isa_Tahiri.

      The scope have changed slightly. We have an admin xaf application that determines the databases that are linked to a specific user. Upon a successful login, we query the admin application to determine if the user is linked to multiple databases. if the User is linked to multiple databases, then we need to present a list for him or her to select a db before the main form opens. If it happens that the user is linked to only one db, then there will be no need to select the database.

      Thanks so much for your response.

      Kind regards.

        Hi,

        As said, not yet finished.
        The easy way would be the authentication detailview with the dropdown editor listing dbs and having some conditional appearance and filling dynamically.

        Conditional appearance : Hide If more that one record.
        Filling dynamically : see https://docs.devexpress.com/eXpressAppFramework/112681/filtering/in-list-view/how-to-implement-cascading-filtering-for-lookup-list-views#4

        The convenient idea would be Wizard --> See https://github.com/eXpandFramework/Reactive.XAF/tree/master/src/Modules/ViewWizard

        I let DX team support u if it's urgent case in ticket T1030070.

        BR
        ISA

          Thank you very much Isa, I will explore your suggestion.

          Kind regards.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.