Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 769
Dave Nichol Avatar asked Feb 13 '26 04:02

Dave Nichol


1 Answers

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.

like image 102
Antony Denyer Avatar answered Feb 20 '26 13:02

Antony Denyer