Ticket T1192806
Visible to All Users

How to use dependency injection in modules

created a year ago (modified a year ago)

[DevExpress Support Team: CLONED FROM T1191645: How to always call the database updater in E1344 (for scheme changes based on tenants)]
I am trying to add Custom Modules to a solution, based on the tennant.
To perform that, I wrote a test in Blazor Module:

C#
[ActivatorUtilitiesConstructor] public BlazorModule(ICurrentTennant tennant):this() { this._tennant = tennant; if (tennant.Code.ToLower() == "test") this.RequiredModuleTypes.Add(typeof(TestModule)); } public BlazorModule() : base() { }

It seems not to work.
How to inject in ModuleBase?

Answers approved by DevExpress Support

created a year ago

Hello Michael,

This approach works only for Controllers. To get a service in a module, use the XafApplication.ServiceProvider property, as described in our documentation:
Dependency Injection (DI)
Register Services in the Dependency Injection Container

An XafApplication is passed to a module in the ModuleBase.Setup method: How to: Show Notifications to a Specific User.

    Show previous comments (3)
    Dennis Garavsky (DevExpress) a year ago

      Thanks for your warm words, Michael. It's not that we are unwilling to implement this functionality - we want to have it just like you do. This year we are just focusing on the things from our roadmap at https://community.devexpress.com/blogs/xaf/archive/2023/08/24/xaf-cross-platform-net-app-ui-amp-web-api-service-year-end-roadmap-v23-2.aspx. As part of this huge undertaking, we hope to ship the first version of our multi-tenancy module with the most requested basic functionality. Then we hope to gather additional user feedback and iterate in v24.1, v24.2 or even drop this idea completely, if our implementation does not have the same traction, for instance, as our Web API Service did a year ago. If you read my previous roadmaps, then you also saw that feature licensing or module management for tenants is a part of our long-term vision. It's just not planned for this year, because we have more important things to do based on user feedback and our existing resources.

      I also can't give you exact instructions on how to build this feature yourself, because it's like asking me to make a car designed for roads to fly, in your garage (we have not yet done it ourselves yet + it requires architectural changes at the core level, which you will unlikely would be able to implement on your side). It's also not about replacing A with B and overriding C in a few places - it's building a totally new car engine, wheels, and adding wings, probably preserving a similar color or body shape.
      For more information on such advanced tasks, I can only recommend that you study the source code of XAF's core (like types info system, application model, module manager, XafApplication, etc.), because you will see all the insights and explanations yourself - this sort of tasks is a way beyond our support service regardless how much I am willing to help you.

      As for general directions, I gave you them previously, and that is the best we can do here:

      At present, we recommend that you load all the modules, and disable their features via Controller per user/tenant instead. All the tenants will have the same set of business classes and database tables in their own databases.

      My idea is to act like there are no modules per tenant and setup XafApplication.Modules with all the modules you have, much like in a default XAF project setup. Then, disable certain standard and custom module features based on required conditions at runtime.
      I believe you already implemented such things multiple times considering your past experience with XAF (no Blazor specificities here). Our docs are also full of examples where certain standar or custom features are disabled or added for all or a certain user at runtime:

      Reviewing my advice for advanced tasks from https://www.devexpress.com/products/net/application_framework/xaf-considerations-for-newcomers.xml may also help you.

      I hope this makes sense and helps you move forward the best way for your business/projects. If not, then probably waiting for our potential built-in implementation one day (no promises/ETA) or building your own multi-tenancy solution without XAF are better options for you and your dev team.

      M M
      Michael de Vlieger a year ago

        Hi Dennis,

        I was not trying to offend you by considering unwillingness. There may be a lot of good reasons to not wanting to Implement my personal requests (although I think my requests are all sound ).

        I understand all of what you told and I agree with you. I think it May indeed be too complex to implement it myself. Not working with expressapp does not sound like a great solution for me.

        I will work around it as long as required.and will keep you informed.

        Please note I am used to the freedom of winforms (working with devexpress products since version 7.1) and not that much into web, so I am just trying…

        Dennis Garavsky (DevExpress) a year ago

          No worries, Michael.

          Yeah, the client-server architecture of distributed/Web apps and API services is totally different from "fat" WinForms clients, and requires a lot of additional considerations (unrelated to DevExpress/XAF directly).

          My team and I (and probably other XAFers) will be happy to hear of your results/implementations as you go - thanks.

          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.