Skip to content

Instantly share code, notes, and snippets.

@kevinpang
kevinpang / gist:1917946
Created February 26, 2012 17:51
CreateSessionFactory
public static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey("InsertConnectionString")))
.Mappings(m =>
{
// Include both standard NHibernate mapping files and Fluent NHibernate mapping files
m.HbmMappings.AddFromAssemblyOf<User>();
m.FluentMappings.AddFromAssemblyOf<User>();
})
@kevinpang
kevinpang / gist:1917947
Created February 26, 2012 17:51
ApplicationStart2
protected void Application_Start()
{
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
ObjectFactory.Initialize(x =>
{
// ISessionFactory is expensive to initialize, so create it as a singleton.
x.For<ISessionFactory>()
.Singleton()
.Use(CreateSessionFactory());
@kevinpang
kevinpang / gist:1917961
Created February 26, 2012 17:55
ApplicationEndRequest
protected void Application_EndRequest()
{
// Make sure to dispose of NHibernate session if created on this web request
ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
}
public class You {
private Car myCar = new Car();
public void Drive(IList<Person> passengers, Location destination)
{
foreach (var passenger in passengers)
myCar.AddPassenger(passenger);
myCar.Drive(destination);
}
public class You {
private ICar myCar;
public You(ICar car)
{
myCar = car;
}
public void Drive(IList<Person> passengers, Location destination)
{