Use service within another module

Jun 9, 2008 at 1:38 PM
Dear all,

I created a service in BusinessModule A.

How could I call this service from Business Module B?


Jun 9, 2008 at 3:29 PM
In the module initializer of Business Module A, add the service to global services.

In the configuration section of Business Module B, add a dependency to Business Module A.

In the Business Module B, inject the service when it is needed.

I prefer to move the service to a function module in case there is another service in B which is used by A.

Chester in Calgary
Jun 9, 2008 at 8:36 PM
Edited Jun 9, 2008 at 8:38 PM

Hi Yu,

First, in the ModuleInitializer class of your BusinessModuleA, register the service in the method AddGlobalServices i.e.:

protected virtual void AddGlobalServices(IServiceCollection globalServices)


    globalServices.AddNew<RedirectNavigationService, INavigationService>();


Second, add a reference to the Module A or to the project that contains the interface of the service (if you created a separated project for the interfaces) in the modules that are going to use the services.

Then, you can get a reference to the service where you need it (presenters, controllers… any class built by the object builder), i.e.:

private INavigationService _navigationService;<o:p></o:p>

public CustomersController([ServiceDependency] INavigationService navigationService)


    _navigationService = navigationService;


BTW: It’s recommended to use Foundation Modules for global services and use interfaces projects to avoid cross references between modules.

Please, let me know if it helps,

Jonathan Cisneros

Jun 9, 2008 at 11:01 PM
Thank you so much for the reply.

I will try them out.

Jun 13, 2008 at 10:53 AM

BTW: It’s recommended to use Foundation Modules for global services and use interfaces projects to avoid cross references between modules.

Hi Jonathan,

Thanks for your help.

Would it be possible to give some code smaple regarding the recommendation?

I need to create a lookup service in the foundation module so that every business module is able to use it. Can I put it in the Shell or need to create a new foudation module?



Jul 1, 2008 at 6:53 AM
Hi gengyu,

You can use your Service in another module[B] which you have added in one module[A]. For that you need to do the following things:

1. Create New Foundation Module in your Modules[GlobalModule].
 How to do Help is Here: How to Create foundation Module

2.Add Service Reference here[Say EmployeeServiceReference]. by Add Service Reference

3.Register your service as a Global service in newly added Modules ModuleInitilizer[GlobalModuleInitializer.cs]File's AddGlobalServices and add your service here
         protected virtual void AddGlobalServices(IServiceCollection globalServices)
            globalServices.AddNew<EMPLOYEE, IEmployeeService>();           
4.Now in your web.config of website-Main which as at root of website
  4.1 Locate:<compositeWeb> section
  4.2 under it located <modules> section
  4.3 For whatever module[B] you want to use this service[A/EmployeeService] just add its entry like this:
    <module name="B" assemblyName="B" virtualPath="~/B">
                    <dependency module="Shell"/>
                    <dependency module="GlobalModule"/>

That's it.

How it will locate?

Load Method of your B module initializer it also Hooks GlobalService:

If not works/works let me know..any help needed do post here without any hesitation.

Happy Coding!!

Sep 4, 2008 at 8:05 PM
can you provide a sample? We created NavigationService with foundation module. We have 4-6 business module. Each of this business module has a reference to NavigationService module. If you can give a complete sample of how to register and call navigation service from other business module, by registing service, it will be great.