views:

37

answers:

1

Hi - Im new to IOC and StructureMap and have an n-level application and am looking at how to setup the wirings (ForRequestedType ...) and just want to check with people with more experience that this is the best way of doing it!

I dont want my UI application object to reference my persistence layer directly so am not able to wire everything up in this UI project.

I now have it working by defining a Registry class in each project which wires up the types in the project as needed. The layer above registers its types and also calls the assembly below and looks for registries so that all types are registered throught the hierrachy.

E.g. I have UI, Service, Domain, and Persistence libraries. In my service layer the registry looks like

        Scan(x =>
        {
            x.Assembly("MyPersistenceProject");
            x.LookForRegistries();
        });

        ForRequestedType<IService>().TheDefault.Is.OfConcreteType<MyService>();

Is this a recommended way of doing this in a setup such as this? Are there better ways and what are the advantages / disadvantages of these approaches in this case?

A: 

This sounds good.

If you use default conventions, like having a default implementation OrderSevice for the interface IOrderService you can reduce the wiring by using conventions in StructureMap. The WithDefaultConventions is a method in the Registry to use default conventions. You can also specify your own convention and register it in the registry using the method With, see the StructureMap documentation

Ruben