Search code examples
structuremapopenrasta

How to use StructureMap with OpenRasta


How do I use StructureMap with OpenRasta? Can I use it in place of the internal dependency resolver, or is it only possible to use it in conjunction with the built-in DI (i.e. for my own app's dependencies)?

Thanks


Solution

  • Structure map code is here

    Build it then reference the library. Or you could git submodule it.

    Then add the following code into your openrasta project

    public class DependencyResolver : IDependencyResolverAccessor
    {
        public IDependencyResolver Resolver
        {
            get { return new StructureMapDependencyResolver(ConfigureContainer()); }
        }
    
    
        public static IContainer ConfigureContainer()
        {
            var container = new Container();
            container.Configure(c => c.Scan(s =>
            {
                //normal SM registrations
            }));
    
            return container;
        }
    }
    

    Hope it helps

    p.s Structure Map isn't officially supported, you're probably better off with Castle/Ninject.