0
votes

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.

2

2 Answers

0
votes

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.

0
votes

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.