Check out the Latest Articles:
My Application Framework – Part Three – Windsor Registration and it’s role in Plug-ins

I previously mentioned the bootstrapping task registering everything in classes which implement IWebWindsorRegistration and IBusWindsorRegistration. The way I structure my applications is to have a library of interfaces which perform a specific task and then a library of concrete implementations of those interfaces.

For example I divide my application up into Data classes which use generic repositories to provide data access via nHibernate. Service classes which provide a caching layer on top of these repositories. Validation libraries which provided validation for the Domain Objects. Frontend libraries which consume the services and provide a means to handle web requests, serve pages and fire off messages for the Backend Message Handlers to process. I will get into this in a later article in more detail.

However each concrete library has an Installers folder which contains a class which implements IWebWindsorRegistration and IBusWindsorRegistration and may include something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public void Install(IWindsorContainer container)
{
     container.Register(
          AllTypes.FromThisAssembly().BasedOn<IRoleManagementRoleDatabaseFactory>().Configure(
               component =>
               {
                    component.Named(component.Implementation.Name);
                    component.LifeStyle.Is(LifestyleType.PerWebRequest);
               }).WithService.Base(),
          AllTypes.FromThisAssembly().BasedOn<IRoleManagementRoleUnitOfWork>().Configure(
               component =>
               {
                    component.Named(component.Implementation.Name);
                    component.LifeStyle.Is(LifestyleType.PerWebRequest);
               }).WithService.Base(),
          AllTypes.FromThisAssembly().BasedOn<IRoleManagementRoleRepository>().Configure(
               component =>
               {
                   component.Named(component.Implementation.Name);
                   component.LifeStyle.Is(LifestyleType.PerWebRequest);
               }).WithService.Base()
     );
}

Upon start-up the Windsor Bootstrapper extension executes all of these classes and installs the dependencies into the container. So we have libraries being installed from outside of the bin directory into the container for our application to serve up.

The way this works in the context of serving up content is as so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public void Install(IWindsorContainer container)
{
     container.Register(
          AllTypes.FromThisAssembly().BasedOn<IController>().Configure(
               component =>
               {
                    component.Named(component.Implementation.Name);
                    component.LifeStyle.Is(LifestyleType.Transient);
               }).WithService.Base(),
          AllTypes.FromThisAssembly().BasedOn<WebViewPage>().Configure(
               component =>
               {
                     component.Named(ViewKeyGenerator.GetViewKey(component.Implementation.FullName));
               }).WithService.Base(),
          AllTypes.FromThisAssembly().BasedOn<IRegisterRoutes>().Unless(x => x.IsAbstract).Configure(x => x.LifeStyle.Singleton),
          AllTypes.FromThisAssembly().BasedOn<IRegisterNavigation>().Unless(x => x.IsAbstract).Configure(x => x.LifeStyle.Singleton),
          AllTypes.FromThisAssembly().BasedOn<ICommand>().Unless(x => x.IsAbstract).Configure(x => x.LifeStyle.Transient)
     );
 }

Each frontend project registers all of its controllers, all of its Web Pages using a method I wrote to format it’s implementation name, all of its route registrations, all of its navigation registrations and finally all of its commands that it uses to process user input, ensure its valid before sending a message off to the Bus.

With everything in the container when a request for a controller comes in the Windsor Controller Factory resolves it from the container. When the controller returns its page the page is found in the container and rendered as the result of the request.



  1. It‘s quite in here! Why not leave a response?