Friday, February 25, 2011

FubuMVC - IOC Container

Another niceties of FubuMVC is that it has its own IOC in its heart. Right now just StructureMap is supported but it's been said that other well-known IOC containers might be supported in future (Castle windsor, Autofac,.. even Unity!!)

Look how easy it is to bootstrap IOC in application's startup evet:
 
// ConfigureFubuMVC is explained in the last post
FubuApplication.For()
.ContainerFacility(() =>
{
var container = new Container();
container.Configure(x =>
{
x.AddRegistry(new NHibernateRegistry());
x.Scan(s =>
{
s.TheCallingAssembly();
// scan with a custom IRegistrationConvention
s.Convention();
});
});
return new StructureMapContainerFacility(container);
})
.Bootstrap();
}



And NhibernateRegsitry class contains all information for our interfaces.
    public class NHibernateRegistry : Registry
    {
        public NHibernateRegistry()
        {
            ForSingletonOf().Use();
            For().HybridHttpOrThreadLocalScoped().Use();
            ....
            .......
        }
    }


No comments:

Post a Comment