asp.netasp.net-core.net-coremodularitymodular-design

Asp.Net Core Modular Application


I am building asp.net core 2 modular application, I was having one module but now I am about to create another module and I get to the point that I need to develop a communication between the two modules, I need to use a model class from module A in module B, how can I achieve this without any dependencies between the modules I do not want to put the model class in a shared project nor creating references between modules.


Solution

  • Modules should not depend on another module, it can depend only on contracts. Some example. You have module Awith intrerface IModuleAService and class that implements it, ModuleAService. Module B requires for his service ModuleBSerice implementation of IModuleAService. So create separate assemblies:

    And at your startup class you need register all modules. IoC will make all workds for you. If later you would like to seperate app into two, it will be easy. Case your need to implement proxy to access ModuleA.