public NHibernateCriteriaPaginable(NHibernatePersistenceManager pm,
                                    ICriterion[] criteria,
                                    Order[] order)
 {
     this.persistenceManager = pm;
     this.criteria           = criteria;
     if (order == null)
     {
         this.order = new Order[0];
     }
     else
     {
         this.order = order;
     }
 }
        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>());
        }
Esempio n. 3
0
 public NHibernateRepository(NHibernatePersistenceManager persistenceManager)
 {
     this.persistenceManager = persistenceManager;
 }
Esempio n. 4
0
 public NHibernateRepository(NHibernatePersistenceManager persistenceManager, IContext context)
 {
     this.persistenceManager = persistenceManager;
     this.context            = context;
 }