How-To: Registering services through configuration in WCSF
One of the requested features for the Web Client Software Factory has been the possibility to register global services through the Web.Config file. By registering the services through configuration there is no need to rebuild any module when you want to switch the concrete implementation of a service.
Julián Domínguez and me have been working on this request, and this is what we came up with. If you have any suggestions or doubts, please leave a comment to provide us with feedback.
How to use the library
- Add the following configSection to the compositeWeb sectionGroup:
<sectionGroup name=”compositeWeb”> <section name=”services” type=”CompositeWeb.Extensions.Configuration.ServicesConfigurationSection, CompositeWeb.Extensions”/> <!– Other config sections here –> </sectionGroup>
- Add the services you want to register:
<compositeWeb> <modules> <module name=”Shell” assemblyName=”MyApplication.Modules.Shell” virtualPath=”~/”/> </modules> <services> <service registerAs=”MyInterfaces.IMyService, MyInterfaces” type=”MyImplementations.MyService, MyImplementations”/> </services> </compositeWeb>
The library will load and register these services before initializing any of the modules in your application.
Note: this will register the services as global services.
Necessary changes to your current solution
All you need to do is make your Global.asax inherit from CompositeWeb.Extensions.CustomWebClientApplication (and a reference to the library) for it to do the magic.
<%@ Application Language=”C#” Inherits=”CompositeWeb.Extensions.CustomWebClientApplication” %>
Source code
- You can get the source code of the CompositeWeb.Extensions project by downloading the CompositeWeb.Extensions.zip file below. If you face problems building the solution, make sure the reference to the Composite Web Application Block assembly is correct.
- Important: The code is provided “as is” without warranty of any kind.
Attachment: CompositeWeb.Extensions.zip
Humm… interesting,
Great work.
Thanks for writing about it
Download unfortunately not working.
/Jens