Example #1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            var schemaCreator = new SchemaCreator();

            schemaCreator.CreateSchema();

            var container = new WindsorContainer()
                            .AddFacility <WcfFacility>()
                            .AddFacility <FactorySupportFacility>()
                            .Register(SessionEndPoint)
                            .Register(Component.For <IProductRepository>().ImplementedBy <ProductRepository>())
                            .Register(Service <IProductModel, ProductModel>(9595));

            var nhConfigurator = new DefaultSessionFactoryConfigurationProvider();
            var sfp            = new SessionFactoryProvider(nhConfigurator);

            container.Register(Component.For <ISessionFactoryProvider>().Instance(sfp));
            container.Register(Component.For <ISessionWrapper>().ImplementedBy <SessionWrapper>());
            container.Register(Component.For <ISessionFactory>().Instance(sfp.GetFactory(null)));

            IoC.RegisterResolver(new WindsorDependencyResolver(container));

            CurrentSessionContext.Wrapper = container.Resolve <ISessionWrapper>();

            Console.WriteLine("Server started");
            Console.ReadLine();
            schemaCreator.CreateSchema();
        }
Example #2
0
        public void ShouldCallDefaultNhConfiguration()
        {
            Configuration nhcfg = null;
            var           dc    = new DefaultSessionFactoryConfigurationProvider();

            dc.AfterConfigure += ((sender, args) => nhcfg = args.Configuration);
            dc.Configure();
            Assert.That(nhcfg, Is.Not.Null);
            Assert.That(nhcfg.Properties.ContainsKey(Environment.ConnectionString));
        }
Example #3
0
        public void ShouldNotCallDefaultNhConfigurationIfSelfManagementInTheEvent()
        {
            Configuration nhcfg = null;
            var           dc    = new DefaultSessionFactoryConfigurationProvider();

            dc.BeforeConfigure += ((sender, args) => { nhcfg = args.Configuration;
                                                       args.Configured = true; });
            dc.Configure();
            Assert.That(nhcfg, Is.Not.Null);
            Assert.That(!nhcfg.Properties.ContainsKey(Environment.ConnectionString));
        }
Example #4
0
        public override void Configure(IWindsorContainer container)
        {
            container.AddFacility <PersistenceConversationFacility>();
            container.AddFacility <FactorySupportFacility>();

            NHibernate.Cfg.Environment.BytecodeProvider = new EnhancedBytecode(container);
            var nhConfigurator = new DefaultSessionFactoryConfigurationProvider();

            //sessionFactory part
            var sessionFactoryProvider = new SessionFactoryProvider(nhConfigurator);

            container.Register(Component.For <ISessionFactory>().UsingFactoryMethod(() => sessionFactoryProvider.GetFactory(null)));
            container.Register(Component.For <ISessionFactoryImplementor>().UsingFactoryMethod(() => (ISessionFactoryImplementor)sessionFactoryProvider.GetFactory(null)));

            //uNhAddIns part
            container.Register(Component.For <ISessionFactoryProvider>().Instance(sessionFactoryProvider));
            container.Register(Component.For <ISessionWrapper>().ImplementedBy <SessionWrapper>());
            container.Register(Component.For <IConversationFactory>().ImplementedBy <DefaultConversationFactory>());
            container.Register(Component.For <IConversationsContainerAccessor>().ImplementedBy <NhConversationsContainerAccessor>());

            nhConfigurator.BeforeConfigure += (sender, e) =>
            {
                var nhCfg = e.Configuration;
                nhCfg.RegisterEntityNameResolver();
                RegisterProperties(nhCfg);
                RegisterMappings(nhCfg);
                RegisterListeners(nhCfg);
                RegisterEntityCaches(nhCfg);
                SchemaMetadataUpdater.QuoteTableAndColumns(nhCfg);
                e.Configured = true; // prevent read from Nhibernate.cfg
            };


            nhConfigurator.AfterConfigure += (sender, e) =>
            {
                var nhCfg = e.Configuration;

                //TryUpdateSchema
                var value = ConfigurationManager.AppSettings["SchemaUpdate"];
                if (value.IsNotNullOrEmpty() && value.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
                {
                    new SchemaUpdate(nhCfg).Execute(false, true);
                }
            };



            base.Configure(container);
        }
        static void InitializeNHSessionManagement()
        {
            container.AddFacility <PersistenceConversationFacility>();
            var nhConfigurator = new DefaultSessionFactoryConfigurationProvider();

            nhConfigurator.AfterConfigure += ((sender, e) => new SchemaExport(e.Configuration).Create(false, true));
            var sfp = new SessionFactoryProvider(nhConfigurator);

            container.Register(Component.For <ISessionFactoryProvider>().Instance(sfp));
            // I prefer to use uNhAddIns.LinFuAdapters.SessionWrapper , the discussion: http://groups.google.com/group/unhaddins/browse_thread/thread/e548a6f6a8a444fd
            container.Register(Component.For <ISessionWrapper>().ImplementedBy <SessionWrapper>());
            container.Register(Component.For <ISessionFactory>().Instance(sfp.GetFactory(null)));
            container.Register(Component.For <IConversationFactory>().ImplementedBy <DefaultConversationFactory>());
            container.Register(Component.For <IConversationsContainerAccessor>().ImplementedBy <NhConversationsContainerAccessor>());
        }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            Environment.BytecodeProvider = new EnhancedBytecode(container);


            var nhConfigurator = new DefaultSessionFactoryConfigurationProvider();

            nhConfigurator.BeforeConfigure += (sender, e) => ValidatorInitializer.Initialize(e.Configuration);

            var sfp = new SessionFactoryProvider(nhConfigurator);

            container.Register(Component.For <ISessionFactoryProvider>()
                               .Instance(sfp));
            container.Register(Component.For <ISessionFactory>()
                               .Forward <ISessionFactoryImplementor>()
                               .UsingFactoryMethod(() => container.Resolve <ISessionFactoryProvider>().GetFactory(null)));

            container.Register(Component.For <ISessionWrapper>().ImplementedBy <SessionWrapper>());
            container.Register(Component.For <IConversationFactory>().ImplementedBy <DefaultConversationFactory>());
            container.Register(Component.For <IConversationsContainerAccessor>().ImplementedBy <NhConversationsContainerAccessor>());
        }
Example #7
0
        public IServiceLocator GetServiceLocator()
        {
            var sl = new HomeMadeServiceLocator();

            var nhConfigurator = new DefaultSessionFactoryConfigurationProvider();

            nhConfigurator.AfterConfigure += ((sender, e) => new SchemaExport(e.Configuration).Create(false, true));
            var sfp = new SessionFactoryProvider(nhConfigurator);

            sl.LoadSingletonService <ISessionFactoryProvider>(sfp);

            sl.LoadSingletonService <IConversationFactory>(new DefaultConversationFactory(sfp, new FakeSessionWrapper()));

            sl.LoadSingletonService <IConversationsContainerAccessor>(new NhConversationsContainerAccessor(sfp));

            sl.LoadSingletonService <IDaoFactory>(new DaoFactory(sl));
            sl.LoadDelegatedService(() => sfp.GetFactory(null));
            LoadNaturalnessDaos <Reptile>(sl);
            LoadNaturalnessDaos <Human>(sl);
            LoadNaturalnessModels <Reptile>(sl);
            LoadNaturalnessModels <Human>(sl);
            return(sl);
        }
Example #8
0
        public void ShouldLoadOnlyOneConfiguration()
        {
            var dc = new DefaultSessionFactoryConfigurationProvider();

            Assert.That(dc.Configure().Count(), Is.EqualTo(1));
        }