Created
April 5, 2011 16:15
-
-
Save hyrmn/903914 to your computer and use it in GitHub Desktop.
app_start calls this structuremap bootstrapper
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 static class Bootstrapper | |
{ | |
public static void Initialize() | |
{ | |
StructureMapConfigurator.ConfigureObjectFactory(); | |
ObjectFactory.GetInstance<CitySearchService>().Initialize(); | |
ObjectFactory.GetInstance<StatisticsService>().Initialize(); | |
} | |
} |
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 sealed class NHibernateRegistry : Registry | |
{ | |
public NHibernateRegistry() | |
{ | |
var fluentConfig = Fluently.Configure() | |
.Database(MsSqlConfiguration.MsSql2008 | |
.ConnectionString(c => c.FromConnectionStringWithKey("kfdb")) | |
.ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu") | |
.Cache( | |
c => c.ProviderClass("NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache")) | |
.UseReflectionOptimizer() | |
.DoNot.ShowSql()) | |
.Mappings(m => | |
{ | |
m.HbmMappings.AddFromAssemblyOf<IEntity>(); | |
m.FluentMappings.AddFromAssemblyOf<IEntity>(); | |
}); | |
For<ISessionFactory>().Singleton().Use(fluentConfig.BuildSessionFactory()); | |
For<ISession>().HybridHttpOrThreadLocalScoped().Use(c => c.GetInstance<ISessionFactory>().OpenSession()); | |
} | |
} |
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 static class StructureMapConfigurator | |
{ | |
public static void ConfigureObjectFactory() | |
{ | |
ObjectFactory.Initialize(i => | |
{ | |
i.IgnoreStructureMapConfig = true; | |
i.For(typeof (IDataMapper<>)).Use(typeof (DataMapper<>)); | |
i.AddRegistry(new NHibernateRegistry()); | |
i.AddRegistry(new ServiceRegistry()); | |
i.Scan(s => | |
{ | |
s.Assembly("KennelFinder"); | |
s.WithDefaultConventions(); | |
}); | |
}); | |
} | |
} |
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 StructureMapControllerFactory : DefaultControllerFactory | |
{ | |
protected override IController GetControllerInstance(Type controllerType) | |
{ | |
if (controllerType != null) | |
return ObjectFactory.GetInstance(controllerType) as Controller; | |
return base.GetControllerInstance(controllerType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment