Created
March 2, 2010 21:02
-
-
Save timwingfield/319940 to your computer and use it in GitHub Desktop.
FNH + SM configuration
This file contains hidden or 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
using System; | |
using System.Configuration; | |
using FluentNHibernate; | |
using FluentNHibernate.Cfg; | |
using FluentNHibernate.Cfg.Db; | |
using StructureMap; | |
public static class Bootstrapper | |
{ | |
public static void ConfigureStructureMap() | |
{ | |
ObjectFactory.Initialize(x => | |
{ | |
x.Scan(scan => | |
{ | |
scan.WithDefaultConventions(); | |
scan.With(new RepositoryConventionScanner()); | |
scan.TheCallingAssembly(); | |
}); | |
x.For(typeof(IRepository<>)).Use(typeof(Repository<>)); | |
x.For(typeof(IPhotoRepository)).Use(typeof(PhotoRepository)); | |
x.ForSingletonOf<ISessionSource>() | |
.Use( | |
c => | |
{ | |
var configuration = | |
c.GetInstance<INHibernateConfiguration>().FluentConfiguration; | |
return new SessionSource(configuration); | |
} | |
); | |
}); | |
} | |
} | |
public interface INHibernateConfiguration | |
{ | |
FluentConfiguration FluentConfiguration { get; } | |
} | |
public class NHibernateConfiguration : INHibernateConfiguration | |
{ | |
string dbFile = ConfigurationManager.AppSettings["DBFile"]; | |
public FluentConfiguration FluentConfiguration | |
{ | |
get { | |
return Fluently.Configure() | |
.Database(SQLiteConfiguration.Standard | |
.UsingFile(dbFile)) | |
.Mappings(m => | |
m.FluentMappings.AddFromAssemblyOf<Event>()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment