0

I am using Castle Windsor for ioc in an MVC project.

My architecture is basically Web -> Services -> Data

The controllers have services as dependencies. The services have repositories as dependencies in the data layer.

My Web layer does not have a reference to the Data layer. My problem is that I am trying to register my repositories which is a dependency of my services. If i have a separate container in my services layer that registers the repositories how should I bootstrap it?

Or I may be going about this in the wrong way.

Justin
  • 512
  • 1
  • 8
  • 19
  • Related: http://stackoverflow.com/questions/2096978/what-is-the-correct-layer-to-configure-your-ioc-container-when-using-a-service-la – Mark Seemann Jun 23 '11 at 21:56
  • possible duplicate of [Design - Where should objects be registered when using Windsor](http://stackoverflow.com/questions/1410719/design-where-should-objects-be-registered-when-using-windsor) – Mark Seemann Jun 23 '11 at 21:56

2 Answers2

0

Your Web layer would not have to reference the data layer if you have placed the interafces of the datalayer functional classes ( AKA Repositories ) in the Domain layer. Then you can easily depend upon single container which is initialized in the web layer.

This Question contains further details.

Refer mvc extensions for some advanced way of achieving this.

Community
  • 1
  • 1
Illuminati
  • 4,539
  • 2
  • 35
  • 55
  • So lets say I put the interfaces to my repositories in the domain layer with all the entities. This still doesn't allow me to register which implementation of IRepository to use. – Justin Jun 23 '11 at 18:31
  • answer to that question can be found below - refer to what s1mm0t has done. – Illuminati Jun 23 '11 at 18:39
0

How about this. The downside is that you need to hardcode the Name of your repository dll, but you could always move this to web.config etc which would be slightly cleaner.

IWindsorContainer container = new WindsorContainer();

// Register repositories
_container.Register(
        AllTypes.Pick()
                .FromAssemblyNamed("MyDataLayerAssembly")
                .WithService
                .DefaultInterface());

// Register services
_container.Register(
        AllTypes.Pick()
                .FromAssemblyNamed(typeof(ISomeService).Assembly.GetName().Name)
                .WithService
                .DefaultInterface());

ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

You may just need to tweak precisely what's passed into the Register() methods to suit your needs however.

s1mm0t
  • 6,035
  • 4
  • 38
  • 45