Created
March 1, 2012 16:48
-
-
Save MikeLarned/1951288 to your computer and use it in GitHub Desktop.
MultiTenant StructureMap Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BootStrapper | |
{ | |
public static void MultiTenant(IContainerResolver containerResolver, ITenantSelector tenantSelector) | |
{ | |
ObjectFactory.Configure(x => | |
{ | |
x.For<IContainerResolver>().Use(containerResolver); | |
x.For<ITenantSelector>().Use(tenantSelector); | |
}); | |
} | |
public static void SingleTenant(IConnectionStringProvider connectionStringProvider, IContainerResolver containerResolver) | |
{ | |
ObjectFactory.Container.Configure(x => | |
{ | |
x.For<IContainerResolver>().Use(containerResolver); | |
x.For<ISessionSettings>().Use<SessionSettings>() | |
.Ctor<bool>("script").Is(false) | |
.Ctor<bool>("export").Is(false) | |
.Ctor<bool>("showSql").Is(false) | |
.Ctor<Assembly>("entityAssembly").Is(Assembly.GetAssembly(typeof(Customer))); | |
x.AddRegistry<NHibernateRegistry>(); | |
x.AddRegistry<MembershipRegistry>(); | |
x.AddRegistry(new EventRegistry(Assembly.GetAssembly(typeof(Customer)))); | |
x.Scan(c => | |
{ | |
c.Assembly("Template.Core"); | |
c.TheCallingAssembly(); | |
c.WithDefaultConventions(); | |
}); | |
x.For<IRepository>().Use<Repository>(); | |
x.For<ILogger>().Use<L4NetLogger>(); | |
x.For<IConnectionStringProvider>().Use(connectionStringProvider); | |
x.For<ISessionSource>().HybridHttpOrThreadLocalScoped().Use<SessionSource>(); | |
x.For<ILogger>().Use<L4NetLogger>(); | |
}); | |
} | |
public static Container CreateTenantContainer(IConnectionStringProvider connectionStringProvider) | |
{ | |
Debug.WriteLine("Create container for " + connectionStringProvider.ConnectionString); | |
var container = new Container(); | |
container.Configure(x => | |
{ | |
x.For<ISessionSettings>().Use<SessionSettings>() | |
.Ctor<bool>("script").Is(false) | |
.Ctor<bool>("export").Is(false) | |
.Ctor<bool>("showSql").Is(false) | |
.Ctor<Assembly>("entityAssembly").Is(Assembly.GetAssembly(typeof (Customer))); | |
x.AddRegistry<NHibernateRegistry>(); | |
x.AddRegistry(new EventRegistry(Assembly.GetAssembly(typeof(Customer)))); | |
x.Scan(c => | |
{ | |
c.Assembly("Template.Core"); | |
c.TheCallingAssembly(); | |
c.WithDefaultConventions(); | |
}); | |
x.For<IRepository>().Use<Repository>(); | |
x.For<IConnectionStringProvider>().Use(connectionStringProvider); | |
x.ForSingletonOf<ISessionSource>().Use<SessionSource>(); | |
x.For<ILogger>().Use<L4NetLogger>(); | |
}); | |
return container; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment