protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); //ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); var log4NetPath = Server.MapPath("~/log4net.config"); log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(log4NetPath)); try { var hConfiguration = new NHibernate.Cfg.Configuration(); hConfiguration.AddAssembly("BudgetORM"); hConfiguration.AddAssembly("iSabayaORM"); hConfiguration.AddAssembly("iSabaya.ExtensibleORM"); hConfiguration.AddAssembly("iSabaya.Questionnaire.ORM"); SessionFactory = hConfiguration.BuildSessionFactory(); } catch (Exception exc) { WebLogger.Error(exc.Message); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); log4net.Config.XmlConfigurator.Configure(); MvcHandler.DisableMvcResponseHeader = true; FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); EmailVerifier.RuntimeLicenseKey = "G016NUILAeGgF81JMB03zbbnuDKKCWJhQ9XYfo8HVhhJLA+Uk2l8Jqyqumxb9Pn78MEhaA=="; DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(EmailAttribute), typeof(RegularExpressionAttributeAdapter)); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Core.User.CurrentUserId = "NewWebsite"; foreach (var t in typeof(Area).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(MetaBase)))) { BaseEntity.MetaTypes.Add(t); } var config = new NHibernate.Cfg.Configuration(); config.Configure(); config.AddAssembly(typeof(NHibernateHelper).Assembly); config.AddAssembly(typeof(Page).Assembly); Global.SessionFactory = config.BuildSessionFactory(); }
public static void Configure() { // Configure log4net XmlConfigurator.Configure(); // Configure container CurrentContainer.Container = new WindsorObjectBuilder(); CurrentContainer.Container.RegisterSingleton <IContainer>(CurrentContainer.Container); CurrentContainer.Container.Configure <ContainerControllerFactory>(ComponentInstanciationPolicy.Singleton); // add repositories to container foreach (Type rep in from t in typeof(Student).Assembly.GetTypes() where t.ImplementsGenericDefinition(typeof(NHibernateRepository <>)) select t) { CurrentContainer.Container.Configure(rep, ComponentInstanciationPolicy.Singleton); } // add controllers to container foreach (Type ctl in from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IController).IsAssignableFrom(t) select t) { CurrentContainer.Container.Configure(ctl, ComponentInstanciationPolicy.NewInstance); } // Configure NHibernate var nhibernateCfg = new NHibernate.Cfg.Configuration(); nhibernateCfg.AddProperties(new Dictionary <string, string>() { { NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect" }, { NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider" }, { NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver" }, { NHibernate.Cfg.Environment.ConnectionString, "Data Source=localhost\\SQLEXPRESS;Database=DDDPart1;Integrated Security=SSPI;" }, { NHibernate.Cfg.Environment.QueryTranslator, "NHibernate.Hql.Classic.ClassicQueryTranslatorFactory" }, { NHibernate.Cfg.Environment.Isolation, "ReadCommitted" }, { NHibernate.Cfg.Environment.DefaultSchema, "dbo" }, { NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring" }, { NHibernate.Cfg.Environment.CurrentSessionContextClass, "NHibernate.Context.WebSessionContext" }, }); nhibernateCfg.AddAssembly("Domain"); nhibernateCfg.AddAssembly("Infrastructure.Impl"); CreateSchema(nhibernateCfg); var sessionFactory = nhibernateCfg.BuildSessionFactory(); var persistenceManager = new NHibernatePersistenceManager(sessionFactory); CurrentContainer.Container.RegisterSingleton <NHibernatePersistenceManager>(persistenceManager); // Configure ASP.Net MVC controller factory ControllerBuilder.Current.SetControllerFactory(CurrentContainer.Container.Build <ContainerControllerFactory>()); }
static SessionFactory() { NHConfiguration = new NHibernate.Cfg.Configuration(); NHConfiguration.AddAssembly(Assembly.GetExecutingAssembly().FullName); SchemaMetadataUpdater.QuoteTableAndColumns(NHConfiguration); NHSessionFactory = NHConfiguration.BuildSessionFactory(); }
public void TestFixtureSetUp() { container = new WindsorContainer(); log4net.Config.XmlConfigurator.Configure(); ConfigureWindsorContainer(); Environment.UseReflectionOptimizer = true; Environment.BytecodeProvider = new EnhancedBytecode(container); cfg = new NHibernate.Cfg.Configuration(); cfg.Configure(); cfg.Properties[Environment.ProxyFactoryFactoryClass] = GetProxyFactoryFactory(); cfg.Properties[Environment.CurrentSessionContextClass] = "thread_static"; cfg.RegisterEntityNameResolver(); cfg.Interceptor = GetInterceptor(); cfg.AddAssembly(typeof(IntegrationBaseTest).Assembly); new SchemaExport(cfg).Create(true, true); sessions = (ISessionFactoryImplementor)cfg.BuildSessionFactory(); var componentInterceptor = cfg.Interceptor as Castle.NHibernateInterceptor.ComponentBehaviorInterceptor; if (componentInterceptor != null) { componentInterceptor.SessionFactory = sessions; } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); var configuration = new NHibernate.Cfg.Configuration(); configuration.Configure(); configuration.AddAssembly(typeof(doCS.Models.Project).Assembly); SessionFactory = configuration.BuildSessionFactory(); // Build up your application container and register your dependencies. var builder = new ContainerBuilder(); builder.RegisterControllers(System.Reflection.Assembly.GetExecutingAssembly()); builder.Register(x => SessionFactory.OpenSession()).As<ISession>().HttpRequestScoped(); builder.RegisterType<doCS.Web.Helpers.Implimentation.ProjectContext>().As<doCS.Web.Helpers.IProjectContext>().HttpRequestScoped(); //register extractor helpers builder.RegisterType<doCS.Web.Helpers.Implimentation.Extractor.ExtractorHelper>().As<doCS.Web.Helpers.IExtractorHelper>().HttpRequestScoped(); builder.RegisterType<doCS.Web.Helpers.Implimentation.Extractor.ProjectUpdaterProvider>().InstancePerDependency(); //register extractor dependencies builder.RegisterType<doCS.Extractor.Implementation.Extractor>().As<doCS.Extractor.IExtractor>().HttpRequestScoped(); builder.RegisterType<doCS.Extractor.Implementation.DllExtractor>(); builder.RegisterType<doCS.Extractor.Implementation.XmlExtractor>(); //register view helpers builder.RegisterType<doCS.Web.ViewHelpers.XmlDocumentationHelper>(); _containerProvider = new ContainerProvider(builder.Build()); ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(ContainerProvider)); SetupAutoMapper(); }
static void Main(string[] args) { var configuration = new Configuration() .SetProperty(Environment.ReleaseConnections, "on_close") .SetProperty(Environment.Dialect, typeof(MsSql2008Dialect).AssemblyQualifiedName) .SetProperty(Environment.ConnectionDriver, typeof(SqlClientDriver).AssemblyQualifiedName) .SetProperty(Environment.ConnectionString, ConfigurationManager.ConnectionStrings["db"].ToString()) .SetProperty(Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName); configuration.AddAssembly(typeof(Blog).Assembly); SessionManager.Init(configuration, new SingleSessionStorage()); var session = SessionManager.Current; new SchemaExport(configuration).Execute(false, true, false, session.Connection, null); if (args.Count() > 0) { if (string.Compare(args[0], "/DEMODATA", StringComparison.InvariantCultureIgnoreCase) == 0) { DemoData.SetupData(session); } } }
public static void Init(IHostingEnvironment env) { try { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); string path = string.Empty; if (string.IsNullOrEmpty(configfilepath)) { // var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment; path = System.IO.Path.Combine(env.ContentRootPath, "hibernate.cfg.xml"); //path = @"D:\Suresh\BickBucket\src\Api.Socioboard\hibernate.cfg.xml"; } else { path = configfilepath; } config.Configure(path); config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml sFactory = config.BuildSessionFactory(); } catch (Exception ex) { throw ex; //Console.Write(ex.StackTrace); //logger.Error(ex.Message); } }
private void PrepareSessionFactory(string connectionString) { IDictionary <string, string> properties = new Dictionary <string, string> { { "connection.driver_class", "NHibernate.Driver.MySqlDataDriver" }, { "connection.connection_string", connectionString }, { "proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle" }, { "dialect", "NHibernate.Dialect.MySQL5Dialect" } }; NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration(); configuration.SetProperties(properties); foreach ( FileInfo file in new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "database")).GetFiles("*.dll")) { configuration.AddAssembly(Assembly.LoadFile(file.FullName)); } _nHibernateSessionFactory = configuration.BuildSessionFactory(); }
public static void Init() { try { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); string path = string.Empty; string wanted_path = System.IO.Directory.GetCurrentDirectory(); if (string.IsNullOrEmpty(configfilepath)) { path = wanted_path + "\\hibernate.cfg.xml"; } else { path = configfilepath; } config.Configure(path); config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml sFactory = config.BuildSessionFactory(); } catch (Exception ex) { throw ex; //Console.Write(ex.StackTrace); //logger.Error(ex.Message); } }
public void InitSessionFactory() { try { string connectionString = "Data Source=Pets.sdf"; string owner = String.Empty; NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration(); configuration.Properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect"); configuration.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver"); AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); configuration.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); configuration.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); configuration.Properties.Add("connection.connection_string", connectionString); configuration.Properties.Add("show_sql", "true"); configuration.AddAssembly("DataDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); //ToDo :: Add more entity assembly keys if you nHibernate stuff crashes and you don't know why... _sessionFactory = configuration.BuildSessionFactory(); } catch (Exception ex) { Trace.TraceInformation("Creating the session factory failed with {0}", ex.Message); } }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); // NHibernate configuration var configuration = new NHibernate.Cfg.Configuration(); configuration.Configure(); configuration.AddAssembly(typeof(Log).Assembly); ISessionFactory sessionFactory = configuration.BuildSessionFactory(); // Ninject Ninject.IKernel container = new StandardKernel(); // Set Web API Resolver GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(container); container.Bind <ISessionFactory>().ToConstant(sessionFactory); container.Bind <ISessionManager>().To <SessionManager>(); container.Bind <IRepository>().To <GenericRepository>(); container.Bind <IApplicationService>().To <ApplicationService>(); container.Bind <ITokenService>().To <TokenService>(); container.Bind <ILogService>().To <LogService>(); container.Bind <IApplicationMapper>().To <ApplicationMapper>(); }
/// <summary> /// Builds the session factory with the given properties. Database is updated if updateSchema is set /// </summary> /// <param name="nhibernateProperties"></param> /// <param name="updateSchema"></param> /// <returns></returns> public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema) { var model = Create.SagaPersistenceModel(typesToScan); var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct(); var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties); foreach (var assembly in scannedAssemblies) { nhibernateConfiguration.AddAssembly(assembly); } var fluentConfiguration = Fluently.Configure(nhibernateConfiguration) .Mappings(m => m.AutoMappings.Add(model)); ApplyDefaultsTo(fluentConfiguration); if (updateSchema) { UpdateDatabaseSchemaUsing(fluentConfiguration); } try { return fluentConfiguration.BuildSessionFactory(); } catch (FluentConfigurationException e) { if (e.InnerException != null) throw new ConfigurationErrorsException(e.InnerException.Message, e); throw; } }
public void InitSessionFactory() { try { string connectionString = "Data Source=Pets.sdf"; string owner = String.Empty; NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration(); configuration.Properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect"); configuration.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver"); AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); configuration.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); configuration.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); configuration.Properties.Add("connection.connection_string", connectionString); configuration.Properties.Add("show_sql", "true"); configuration.AddAssembly("DataDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); //ToDo :: Add more entity assembly keys if you nHibernate stuff crashes and you don't know why... _sessionFactory = configuration.BuildSessionFactory(); } catch (Exception ex) { Trace.TraceInformation("Creating the session factory failed with {0}", ex.Message); } }
public static void Main(string[] args) { IList<Product> products; // Don't need to use schema export because of the hbm2dll property. var cfg = new NHibernate.Cfg.Configuration(); cfg.Configure(); // ensure that mapping hbm.xml file is loaded cfg.AddAssembly(typeof(MainClass).Assembly); Product p = new Product() {Name="Captains of Crush Gripper #1", Category="fitness" }; ISessionFactory factory = cfg.BuildSessionFactory(); using (ISession session = factory.OpenSession()) { session.Save(p); session.Flush(); ICriteria sc = session.CreateCriteria<Product>(); products = sc.List<Product>(); Console.WriteLine(products[0].Name); session.Close(); } factory.Close(); Console.WriteLine( products.Count ); Console.WriteLine ("Hello World!"); }
static void Main(string[] args) { NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); cfg.AddAssembly("DomainObjects"); ISessionFactory sessionFactory = cfg.BuildSessionFactory(); }
/// <summary> /// Builds the session factory with the given properties. Database is updated if updateSchema is set /// </summary> /// <param name="nhibernateProperties"></param> /// <param name="updateSchema"></param> /// <returns></returns> public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema) { var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct(); var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties); foreach (var assembly in scannedAssemblies) nhibernateConfiguration.AddAssembly(assembly); var mapping = new SagaModelMapper(typesToScan.Except(nhibernateConfiguration.ClassMappings.Select(x => x.MappedClass))); HackIdIntoMapping(mapping); nhibernateConfiguration.AddMapping(mapping.Compile()); ApplyDefaultsTo(nhibernateConfiguration); if (updateSchema) UpdateDatabaseSchemaUsing(nhibernateConfiguration); try { return nhibernateConfiguration.BuildSessionFactory(); } catch (Exception e) { if (e.InnerException != null) throw new ConfigurationErrorsException(e.InnerException.Message, e); throw; } }
private static void Init() { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); config.AddAssembly(typeof(Product).Assembly); _factory = config.BuildSessionFactory(); }
/// <summary> /// Create an NHibernate configuration class. /// </summary> /// <param name="options">Configuration options.</param> /// <returns>The configuration.</returns> public NHibernate.Cfg.Configuration CreateNHibernateConfiguration(ConfigurationFlags options) { var configuration = new NHibernate.Cfg.Configuration(); if ((options & ConfigurationFlags.Settings) == ConfigurationFlags.Settings) { configuration.SetProperty("hibernate.connection.connection_string", ConnectionConnectionString); configuration.SetProperty("hibernate.connection.provider", ConnectionProvider); configuration.SetProperty("hibernate.connection.driver_class", ConnectionDriverClass); configuration.SetProperty("hibernate.show_sql", ShowSql.ToString(CultureInfo.InvariantCulture).ToUpper( CultureInfo.InvariantCulture)); configuration.SetProperty("hibernate.dialect", Dialect); } if ((options & ConfigurationFlags.Mappings) == ConfigurationFlags.Mappings) { foreach (Assembly assembly in MappingAssemblies) { configuration.AddAssembly(assembly); } } if ((options & ConfigurationFlags.Interceptor) == ConfigurationFlags.Interceptor) { configuration.SetInterceptor(Interceptor); } return(configuration); }
public static void Init() { try { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); string path = string.Empty; string wanted_path = System.IO.Directory.GetCurrentDirectory(); if (string.IsNullOrEmpty(configfilepath)) { // var appEnv = CallContextServiceLocator.Locator.ServiceProvider //.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment; // path = System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "hibernate.cfg.xml"); //path = System.Reflection.Assembly.GetExecutingAssembly().Location; // path = @"D:\bitbucket\Updated\src\SocioboardDataServices\hibernate.cfg.xml"; path = wanted_path + "\\hibernate.cfg.xml"; } else { path = configfilepath; } config.Configure(path); config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml sFactory = config.BuildSessionFactory(); } catch (Exception ex) { throw ex; //Console.Write(ex.StackTrace); //logger.Error(ex.Message); } }
public static NHibernate.ISessionFactory GetSessionFactory( string connectionString, List<String> DllNames) { NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); // set provider & driver properties cfg.Properties.Add( "connection.provider", "NHibernate.Connection.DriverConnectionProvider"); cfg.Properties.Add( "connection.driver_class", "NHibernate.Driver.SQLite20Driver"); cfg.Properties.Add( "dialect", "NHibernate.Dialect.SQLiteDialect"); cfg.Properties.Add( "max_fetch_depth","-1"); // allows for unlimited outer joins (recommeded value is maximum 4 cfg.Properties.Add( "connection.connection_string", ConfigurationManager.ConnectionStrings[connectionString].ConnectionString); cfg.Properties.Add("connection.isolation", "ReadCommitted"); cfg.Properties.Add("query.substitutions", "true 1, false 0"); // here we add all the needed assemblies that contain mappings or objects foreach (String assemblyName in DllNames) cfg.AddAssembly(System.Reflection.Assembly.Load(assemblyName)); return cfg.BuildSessionFactory(); }
/// <summary>Adds default assemblies to NHibernate configuration.</summary> /// <param name="cfg"></param> protected virtual void AddAssemblies(NHibernate.Cfg.Configuration cfg) { foreach (Assembly a in Assemblies) { cfg.AddAssembly(a); } Debug.WriteLine(String.Format("Added {0} assemblies to configuration", Assemblies.Count)); }
public Database() { var configuration = new NHibernate.Cfg.Configuration(); configuration.Configure(); configuration.AddAssembly(Assembly.GetExecutingAssembly()); sessionFactory = configuration.BuildSessionFactory(); }
/// <summary> /// Configurates and instanciates a Nhibernate session factory. /// </summary> static NHibernateHelper() { var configuration = new NHibernate.Cfg.Configuration(); configuration.AddAssembly(Config.Tracer.TracerNhibernateAssembly); SessionFactory = configuration.BuildSessionFactory(); }
protected virtual void ConfigureSessionFactory(Configuration config, string databaseName, string assemblyName, string dialect, string connectionDriver, string connectionString) { config.SetProperty(Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider"); config.SetProperty(Environment.Dialect, dialect); config.SetProperty(Environment.ConnectionDriver, connectionDriver); config.SetProperty(Environment.ConnectionString, connectionString); config.SetProperty(Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); config.AddAssembly(assemblyName); }
public BaseContext() { try { var hConfiguration = new NHibernate.Cfg.Configuration(); hConfiguration.AddAssembly("BudgetORM"); hConfiguration.AddAssembly("iSabayaORM"); hConfiguration.AddAssembly("iSabaya.ExtensibleORM"); sessionFactory = hConfiguration.BuildSessionFactory(); BudgetConfiguration.SessionFactory = sessionFactory; context = new SessionContext(new iSystem(SystemEnum.RiskAssessmentAdminSystem), sessionFactory); } catch (Exception) { } }
public static ISessionFactory GetSessionFactory() { var configuration = new NHibernate.Cfg.Configuration(); configuration.Configure(); configuration.AddAssembly(typeof(SessionFactoryFactory).Assembly.GetName().Name); log4net.Config.XmlConfigurator.Configure(); var sessionFactory = configuration.BuildSessionFactory(); return sessionFactory; }
private static Configuration RecuperaConfiguracao() { Configuration cfg = new Configuration(); cfg.Configure(); cfg.AddAssembly(Assembly.GetExecutingAssembly()); return(cfg); }
public void CanGenerateSchema() { var cfg = new NHibernate.Cfg.Configuration(); cfg.Configure(); cfg.AddAssembly(Assembly.Load("InfoHub.Entity")); new SchemaExport(cfg).Execute(false, true, false); }
private static void LoadAssembly(string assemblyAppSettingKey, NHibernate.Cfg.Configuration configuration) { try { configuration.AddAssembly("DataDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); } catch (Exception ex) { Trace.TraceInformation(ex.Message); } }
public static ISessionFactory GetSessionFactory() { var configuration = new NHibernate.Cfg.Configuration(); configuration.Configure(); configuration.AddAssembly(typeof(SessionFactoryFactory).Assembly.GetName().Name); log4net.Config.XmlConfigurator.Configure(); var sessionFactory = configuration.BuildSessionFactory(); return(sessionFactory); }
/// <summary> /// The main method for the application. /// </summary> /// <param name="args"> /// The command-line arguments. /// </param> public static void Main(string[] args) { NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration(); configuration.Configure(); configuration.AddAssembly(typeof(Manufacturer).Assembly); new SchemaExport(configuration).Execute(true, false, true); Application.Init(); MainWindow win = new MainWindow(); win.Show(); Application.Run(); }
static void Generate() { var cfg = new NHibernate.Cfg.Configuration(); cfg.Configure(); cfg.AddAssembly(typeof(Job).Assembly); //var n = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false); var export = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg); export.Create(false, true); }
public void StartService() { try { log4net.Config.XmlConfigurator.Configure(); logger = LogManager.GetLogger("root"); AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; logger.Info("Balcony Server Started."); User.CurrentUserId = "system"; do { try { var config = new NHibernate.Cfg.Configuration(); config.Configure(); config.AddAssembly(typeof(NHibernateHelper).Assembly); Global.SessionFactory = config.BuildSessionFactory(); } catch (Exception ex) { logger.Error("BuildSessionFactory", ex); Thread.Sleep(1000); } } while (Global.SessionFactory == null); this.scheduler = StdSchedulerFactory.GetDefaultScheduler(); this.scheduler.Start(); ConfigureJobs(); exchangeServiceUrl = Global.GetConfigValue("ExchangeServiceUrl", "https://remote.balconette.co.uk/EWS/Exchange.asmx"); exchangeServiceUsername = Global.GetConfigValue("ExchangeServiceUsername", "journal"); exchangeServicePassword = Global.GetConfigValue("ExchangeServicePassword", "a9215361"); exchangeServiceDomain = Global.GetConfigValue("ExchangeServiceDomain", "BALCONY"); Thread.Sleep(2000); tmrFetchSystemActions = new Timer(Global.GetConfigValue("ActionsFetchInterval", 60000)); tmrFetchSystemActions.Elapsed += tmrFetchSystemActions_Elapsed; tmrFetchSystemActions.Start(); tmrFetchDistributionLists = new Timer(Global.GetConfigValue("DistributionListsFetchInterval", 60000)); tmrFetchDistributionLists.Elapsed += tmrFetchDistributionLists_Elapsed; tmrFetchDistributionLists.Start(); tmrAutomation = new Timer(Global.GetConfigValue("AutomationInterval", 18000)); tmrAutomation.Elapsed += tmrAutomation_Elapsed; tmrAutomation.Start(); } catch (Exception ex) { logger.Error("OnStart", ex); Stop(); } }
/// <summary> /// Setup NHibernate and connect to the database /// </summary> /// <returns></returns> private void InitialiseDB() { // // Setup database connection // // (1) Configure NHibernate // // - NB. We should be able to do this from a configuration object // - Also there may be versioning issues with log4net ? // // string strDirectory = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName; try { Logger.Debug("Bringing up NHibernate"); NhibernateCfg = new NHibernate.Cfg.Configuration(); if (useDevDatabaseToolStripMenuItem.Checked) { if (!string.IsNullOrEmpty(Globals.DevelopmentDBURI)) { Logger.Warn("*** OVERRIDING WITH DEV DATABASE ***"); NhibernateCfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, Globals.DevelopmentDBURI); } else { throw new ArgumentException("*** NO DEV DATABASE DEFINED ***"); } } else { if (!string.IsNullOrEmpty(Globals.ProductionDBURI)) { NhibernateCfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, Globals.ProductionDBURI); } else { throw new ArgumentException("*** NO PRODUCTION DATABASE DEFINED ***"); } } NhibernateCfg.AddAssembly("DynamicDevices.Testing.DAO"); Logger.Debug("Now building external DB session factory"); Nhibernatefactory = NhibernateCfg.BuildSessionFactory(); Session = Nhibernatefactory.OpenSession(); } catch (Exception e) { Logger.Warn("Exception bringing up NHibernate: " + e.Message); } return; }
/// <summary> /// Setup NHibernate and connect to the database /// </summary> /// <returns></returns> private void InitialiseDB() { // // Setup database connection // // (1) Configure NHibernate // // - NB. We should be able to do this from a configuration object // - Also there may be versioning issues with log4net ? // // string strDirectory = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName; try { Logger.Debug("Bringing up NHibernate"); NhibernateCfg = new NHibernate.Cfg.Configuration(); if (useDevDatabaseToolStripMenuItem.Checked) { if (!string.IsNullOrEmpty(Globals.DevelopmentDBURI)) { Logger.Warn("*** OVERRIDING WITH DEV DATABASE ***"); NhibernateCfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, Globals.DevelopmentDBURI); } else { throw new ArgumentException("*** NO DEV DATABASE DEFINED ***"); } } else { if (!string.IsNullOrEmpty(Globals.ProductionDBURI)) { NhibernateCfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, Globals.ProductionDBURI); } else { throw new ArgumentException("*** NO PRODUCTION DATABASE DEFINED ***"); } } NhibernateCfg.AddAssembly("DynamicDevices.Testing.DAO"); Logger.Debug("Now building external DB session factory"); Nhibernatefactory = NhibernateCfg.BuildSessionFactory(); Session = Nhibernatefactory.OpenSession(); } catch (Exception e) { Logger.Warn("Exception bringing up NHibernate: " + e.Message); } return; }
public static NHibernate.Cfg.Configuration CreateConfiguration() { IDictionary<string, string> props = new Dictionary<string, string>(); props["connection.driver_class"] = "NHibernate.Driver.SQLite20Driver"; props["dialect"] = "NHibernate.Dialect.SQLiteDialect"; props["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider"; props["connection.connection_string"] = string.Format(@"Data Source=|DataDirectory|\{0};Version=3;New=True", "NHibernate.Generics.Test.SQLite"); NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); cfg.Properties = props as IDictionary; cfg.AddAssembly(Assembly.GetExecutingAssembly()); return cfg; }
public static void SetContext() { try { var hConfiguration = new NHibernate.Cfg.Configuration(); hConfiguration.AddAssembly("BudgetORM"); hConfiguration.AddAssembly("iSabayaORM"); hConfiguration.AddAssembly("iSabaya.ExtensibleORM"); ISessionFactory sessionFactory = hConfiguration.BuildSessionFactory(); context = new SessionContext(new iSystem(SystemEnum.RiskAssessmentAdminSystem), sessionFactory); if (context == null) { throw new Exception("Can't create context."); } } catch (Exception exc) { } }
/// <summary> /// Registers the assemblies. /// </summary> /// <param name="cfg">The CFG.</param> /// <param name="facilityConfig">The facility config.</param> protected void RegisterAssemblies(Configuration cfg, IConfiguration facilityConfig) { if (facilityConfig == null) return; foreach (IConfiguration item in facilityConfig.Children) { String assembly = item.Value; cfg.AddAssembly(assembly); GenerateMappingFromAttributesIfNeeded(cfg, assembly); } }
public Repository() { NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); cfg.AddAssembly("UserCollection.Entities"); ISessionFactory sessionFactory = cfg.BuildSessionFactory(); _session = sessionFactory.OpenSession(); if (_session == null) { throw new InvalidOperationException(@"Unable to open session on database connection."); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); var log4NetPath = Server.MapPath("~/log4net.config"); log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(log4NetPath)); try { var hConfiguration = new NHibernate.Cfg.Configuration(); hConfiguration.AddAssembly("BudgetORM"); hConfiguration.AddAssembly("iSabayaORM"); hConfiguration.AddAssembly("iSabaya.ExtensibleORM"); SessionFactory = hConfiguration.BuildSessionFactory(); } catch //(Exception exc) { } }
private NHibernate.Cfg.Configuration BuildNHibernateConfiguration(string connectionString) { IDictionary<string, string> configPropertyTable = new Dictionary<string, string>(this.StaticConfigPropertyTable); configPropertyTable[NHibernateProviderManager.ConnectionStringKey] = connectionString; var config = new NHibernate.Cfg.Configuration().SetProperties(configPropertyTable); foreach (var assemblyName in this.XmlMappingAssemblyNames) { config.AddAssembly(assemblyName); } return config; }
public static void configSession() { //gets the connection string data associated with this db string dsn = ConfigurationManager.ConnectionStrings[connectionString].ConnectionString; config = new NHibernate.Cfg.Configuration(); config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider"); config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSqlCeDialect"); config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver"); config.SetProperty("hibernate.show_sql", "true"); config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, dsn); ///important to add assembly, which is the name of the app or project usually; config.AddAssembly("OnBudgetApp"); SessionFactory = config.BuildSessionFactory(); }
/// <summary> /// Static constructor /// Inintializes default settings /// </summary> static Settings() { _connectionString = ""; _isDebug = false; Configuration cfg = new Configuration(); IDictionary section = ConfigurationManager.GetSection(NhibernateSectionName) as IDictionary; if (section == null) { throw new NHibernateSectionLoadException(); } cfg.AddProperties(section); cfg.AddAssembly(typeof(Settings).Assembly); _sessionFactory = cfg.BuildSessionFactory(); }
/// <summary> /// Creates NHibernate Session Factory. /// </summary> /// <returns>NHibernate Session Factory</returns> private static ISessionFactory CreateNhSessionFactory(IKernel kernel, CreationContext context) { NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration().Configure(); cfg.AddAssembly("Konekti.Model"); // update schema or create one if not exist new SchemaUpdate(cfg).Execute(false, true); return cfg.BuildSessionFactory(); /*string connStr = ConfigurationManager.ConnectionStrings["Konekti"].ConnectionString; return Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(connStr)) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(MenuGroup)))) .BuildSessionFactory();*/ }
public void MakeConnection(User user) { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); config.Configure().Configure("hibernate.cfg.xml"); config.AddAssembly(typeof(User).Assembly); NHibernate.ISessionFactory factory = config.BuildSessionFactory(); NHibernate.ISession session = factory.OpenSession(); // NHibernate.ITransaction transaction = session.BeginTransaction(); /* Console.Write("Saving"); session.Save(user); */ IQuery iquery = session.CreateQuery("from User u where u.Username='******'"); IList<User> returnUser = iquery.List<User>(); Console.Write(returnUser[0].Age); // transaction.Commit(); session.Close(); }
private ISessionFactory GetSessionFactory() { Configuration cfg = new Configuration().Configure(); //bool useFluent = false; //if (useFluent) //{ //var persistenceModel = new PersistenceModel(); //persistenceModel.addMappingsFromAssembly(Assembly.Load(_mappingAssembly)); //persistenceModel.Configure(cfg); //} //else //{ cfg.AddAssembly(Assembly.Load(_mappingAssembly)); //cfg.AddAssembly(Assembly.Load("Alexandria.Model")); //} return cfg.BuildSessionFactory(); }
/// <summary> /// initializes the session for database /// </summary> private static void Init() { try { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); //string path = HttpContext.Current.Server.MapPath("~/hibernateconfigfile"); //config.Configure(path); Assembly assem=Assembly.GetExecutingAssembly(); config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml sFactory = config.BuildSessionFactory(); } catch (Exception ex) { GlobusLogHelper.log.Error("Error : " + ex.StackTrace); } }
public void MyTestInitialize() { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); config.Properties["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver"; config.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider"; config.Properties["connection.connection_string"] = Helper.ClassicTestDB_SQLExpress_ConnectionString; config.Properties["dialect"] = "NHibernate.Dialect.MsSql2008Dialect"; config.Properties["proxyfactory.factory_class"] = "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"; config.AddAssembly(typeof(Customer).Assembly); NHibernate.Tool.hbm2ddl.SchemaExport schemaExport = new NHibernate.Tool.hbm2ddl.SchemaExport(config); schemaExport.Execute(false, true, false); customer = new Customer { //Id = Guid.NewGuid(), Birth = DateTime.Now, Email = "*****@*****.**", FirstName = "dax", LastName = "net", Password = "******", Username = "******" }; }
public static void Init() { try { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); string path = string.Empty; if (string.IsNullOrEmpty(configfilepath)) { path = HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml"); } else { path = configfilepath; } config.Configure(path); config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml sFactory = config.BuildSessionFactory(); } catch (Exception ex) { logger.Error(ex.Message); } }
public static void Init(HttpApplication httpApplication) { ObjectFactory.Initialize( x => { x.ForRequestedType<IBlogRepository>().TheDefaultIsConcreteType<BlogRepository>(); } ); var configuration = new Configuration() .SetProperty(Environment.ReleaseConnections, "on_close") .SetProperty(Environment.Dialect, typeof(MsSql2008Dialect).AssemblyQualifiedName) .SetProperty(Environment.ConnectionDriver, typeof(SqlClientDriver).AssemblyQualifiedName) .SetProperty(Environment.ConnectionString, ConfigurationManager.ConnectionStrings["db"].ToString()) .SetProperty(Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName); configuration.AddAssembly(typeof(Blog).Assembly); SessionManager.Init(configuration, new HttpSessionStorage(httpApplication)); }
public static ISessionFactory GetSessionFactory() { if (sessionFactorySingleton == null) { var connectionString = GetConnectionString(ConfigurationManager.AppSettings["Import.ConnectionString"]); var properties = new Dictionary<string, string> { { "connection.driver_class", "NHibernate.Driver.SqlClientDriver" }, { "dialect", "NHibernate.Dialect.MsSql2005Dialect" }, { "connection.provider", "NHibernate.Connection.DriverConnectionProvider" }, { "connection.connection_string", connectionString }, }; var configuration = new NHibernate.Cfg.Configuration(); configuration.AddProperties(properties); configuration.AddAssembly(Assembly.GetExecutingAssembly()); sessionFactorySingleton = configuration.BuildSessionFactory(); } return sessionFactorySingleton; }
public static void Init() { try { NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); string path = string.Empty; if (string.IsNullOrEmpty(configfilepath)) { path = HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml"); } else { path = configfilepath; } config.Configure(path); config.AddAssembly("SocioBoard");//adds all the embedded resources .hbm.xml sFactory = config.BuildSessionFactory(); } catch (Exception ex) { Console.WriteLine("Error : " + ex.StackTrace); } }
/// <summary> /// Initializes the session factory and ensure that the /// configuration file exists. /// </summary> private void InitSessionFactory() { //expect the hibernate.cfg.xml file to be in the application folder NHibernate.Cfg.Configuration temp = new NHibernate.Cfg.Configuration(); cfg = temp.Configure(); cfg.AddAssembly("gooeycms.data"); //build the session factory based upon the configuration sessionFactory = cfg.BuildSessionFactory(); }
public static void Configure() { // Configure log4net XmlConfigurator.Configure(); // Configure container CurrentContainer.Container = new WindsorObjectBuilder(); CurrentContainer.Container.RegisterSingleton<IContainer>(CurrentContainer.Container); CurrentContainer.Container.Configure<ContainerControllerFactory>(ComponentInstanciationPolicy.Singleton); CurrentContainer.Container.Configure<ContainerCommandBus>(ComponentInstanciationPolicy.Singleton); CurrentContainer.Container.Configure<ContainerEventBus>(ComponentInstanciationPolicy.Singleton); CurrentContainer.Container.Configure<WebContext>(ComponentInstanciationPolicy.Singleton); // add repositories to container for each type of aggregate roots foreach (Type agg in from t in typeof(Student).Assembly.GetTypes() where typeof(IAggregateRoot).IsAssignableFrom(t) select t) { var rep = typeof(NHibernateRepository<>).MakeGenericType(agg); CurrentContainer.Container.Configure(rep, ComponentInstanciationPolicy.Singleton); } // add DTO queries foreach (Type queries in from t in typeof(StudentDTO).Assembly.GetTypes() where typeof(DTOQueries).IsAssignableFrom(t) select t) { CurrentContainer.Container.Configure(queries, ComponentInstanciationPolicy.Singleton); } // add command handlers foreach (Type handlers in from t in typeof(CreateClassCommandHandler).Assembly.GetTypes() where t.ImplementsGenericDefinition(typeof(IHandleCommand<>)) select t) { CurrentContainer.Container.Configure(handlers, ComponentInstanciationPolicy.Singleton); } // add event handlers foreach (Type handlers in from t in typeof(ClassCreatedEventHandler).Assembly.GetTypes() where t.ImplementsGenericDefinition(typeof(IHandleEvent<>)) select t) { CurrentContainer.Container.Configure(handlers, ComponentInstanciationPolicy.Singleton); } // add controllers to container foreach (Type ctl in from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IController).IsAssignableFrom(t) select t) { CurrentContainer.Container.Configure(ctl, ComponentInstanciationPolicy.NewInstance); } // Configure aggregate roots AggregateRoot.CreateDelegatesForAggregatesIn(typeof(Student).Assembly); // Configure NHibernate var nhibernateCfg = new NHibernate.Cfg.Configuration(); nhibernateCfg.AddProperties(new Dictionary<string, string>() { {NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect"}, {NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider"}, {NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver"}, {NHibernate.Cfg.Environment.ConnectionString, "Data Source=localhost\\SQLEXPRESS;Database=DDDPart5;Integrated Security=SSPI;"}, {NHibernate.Cfg.Environment.QueryTranslator, "NHibernate.Hql.Classic.ClassicQueryTranslatorFactory"}, {NHibernate.Cfg.Environment.Isolation, "ReadCommitted"}, {NHibernate.Cfg.Environment.DefaultSchema, "dbo"}, {NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring"}, {NHibernate.Cfg.Environment.CurrentSessionContextClass, "NHibernate.Context.WebSessionContext"}, {NHibernate.Cfg.Environment.UseProxyValidator, "false"}, }); nhibernateCfg.AddAssembly("Domain"); nhibernateCfg.AddAssembly("Infrastructure.Impl"); if (ConfigurationManager.AppSettings["ReCreateSchemaAtStartup"] == "true") { ReCreateSchema(nhibernateCfg); } var sessionFactory = nhibernateCfg.BuildSessionFactory(); var persistenceManager = new NHibernatePersistenceManager(sessionFactory, CurrentContainer.Container.Build<IContext>(), CurrentContainer.Container.Build<IEventBus>()); CurrentContainer.Container.RegisterSingleton<NHibernatePersistenceManager>(persistenceManager); // Configure ASP.Net MVC controller factory ControllerBuilder.Current.SetControllerFactory(CurrentContainer.Container.Build<ContainerControllerFactory>()); }
/// <summary> /// Create an NHibernate configuration class /// </summary> /// <returns></returns> public NHibernate.Cfg.Configuration CreateNHibernateConfiguration(ConfigurationFlags options, IInterceptor interceptor) { var configuration = new NHibernate.Cfg.Configuration(); if ((options & ConfigurationFlags.Settings) == ConfigurationFlags.Settings) { configuration.SetProperty("connection.connection_string", Connection_ConnectionString); configuration.SetProperty("connection.provider", Connection_Provider); configuration.SetProperty("connection.driver_class", Connection_DriverClass); configuration.SetProperty("dialect", Dialect); configuration.SetProperty("show_sql", ShowSql.ToString(CultureInfo.InvariantCulture).ToLower()); configuration.SetProperty("proxyfactory.factory_class", ProxyFactoryClass); //Include The TablePrefix Property For the Table Mappings ... RRRM : 23/09/2007 if (!String.IsNullOrEmpty(TablePrefix)) { var ns = (NamingStrategy)NamingStrategy.Instance; ns.Prefix = TablePrefix; configuration.SetNamingStrategy(NamingStrategy.Instance); } } if ((options & ConfigurationFlags.Mappings) == ConfigurationFlags.Mappings) { foreach (var assembly in MappingAssemblies) configuration.AddAssembly(assembly); } if ((options & ConfigurationFlags.Interceptor) == ConfigurationFlags.Interceptor) { if (interceptor != null) configuration.SetInterceptor(interceptor); } if ((options & ConfigurationFlags.MappingsToExport) == ConfigurationFlags.MappingsToExport) { foreach (var assembly in MappingAssembliesToExport) configuration.AddAssembly(assembly); } return configuration; }
public static void AppInit_Repositories_NHibernateRepository(object sender, AppInitEventArgs e) { UnityContainer c = e.ObjectContainer.GetWrappedContainer<UnityContainer>(); NHibernate.Cfg.Configuration nhibernateCfg = new NHibernate.Cfg.Configuration(); nhibernateCfg.Properties["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver"; nhibernateCfg.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider"; nhibernateCfg.Properties["connection.connection_string"] = ClassicTestDB_SQLExpress_ConnectionString; nhibernateCfg.Properties["dialect"] = "NHibernate.Dialect.MsSql2008Dialect"; nhibernateCfg.Properties["proxyfactory.factory_class"] = "NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate"; //nhibernateCfg.Properties["linqtohql.generatorsregistry"] ="Apworks.Repositories.NHibernate.ExtendedLinqToHqlGeneratorsRegistry, Apworks.Repositories.NHibernate"; nhibernateCfg.AddAssembly(typeof(Customer).Assembly); c.RegisterInstance<NHibernate.Cfg.Configuration>(nhibernateCfg) .RegisterType<IRepositoryContext, NHibernateContext>(new InjectionConstructor(new ResolvedParameter<NHibernate.Cfg.Configuration>())) //.RegisterType<IRepository<Customer>, NHibernateRepository<Customer>>(new InjectionConstructor(new ResolvedParameter<IRepositoryContext>())); .RegisterType<IRepository<Customer>, NHibernateRepository<Customer>>(); }
public static void AppInit_Repositories_RegularEventPublisherDomainRepository_MSMQ(object sender, AppInitEventArgs e) { UnityContainer c = e.ObjectContainer.GetWrappedContainer<UnityContainer>(); NHibernate.Cfg.Configuration nhibernateCfg = new NHibernate.Cfg.Configuration(); nhibernateCfg.Properties["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver"; nhibernateCfg.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider"; nhibernateCfg.Properties["connection.connection_string"] = CQRSTestDB_SQLExpress_ConnectionString; nhibernateCfg.Properties["dialect"] = "NHibernate.Dialect.MsSql2008Dialect"; nhibernateCfg.Properties["proxyfactory.factory_class"] = "NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate"; //nhibernateCfg.Properties["linqtohql.generatorsregistry"] = "Apworks.Repositories.NHibernate.ExtendedLinqToHqlGeneratorsRegistry, Apworks.Repositories.NHibernate"; nhibernateCfg.AddAssembly(typeof(SourcedCustomer).Assembly); c.RegisterInstance<NHibernate.Cfg.Configuration>(nhibernateCfg) .RegisterType<IEventBus, MSMQEventBus>(new ContainerControlledLifetimeManager(), new InjectionConstructor(Helper.CreateMessageQueueName(EventBus_MessageQueue), true)) .RegisterType<IRepositoryContext, NHibernateContext>(new InjectionConstructor(new ResolvedParameter<NHibernate.Cfg.Configuration>())) .RegisterType<IRepository<SourcedCustomer>, NHibernateRepository<SourcedCustomer>>() .RegisterType<IDomainRepository, RegularEventPublisherDomainRepository>(new InjectionConstructor(new ResolvedParameter<IRepositoryContext>(), new ResolvedParameter<IEventBus>())); }
private void PrepareSessionFactory(string connectionString) { IDictionary<string, string> properties = new Dictionary<string, string> { { "connection.driver_class", "NHibernate.Driver.MySqlDataDriver" }, {"connection.connection_string", connectionString}, { "proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle" }, {"dialect", "NHibernate.Dialect.MySQL5Dialect"} }; NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration(); configuration.SetProperties(properties); foreach ( FileInfo file in new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "database")).GetFiles("*.dll")) { configuration.AddAssembly(Assembly.LoadFile(file.FullName)); } _nHibernateSessionFactory = configuration.BuildSessionFactory(); }