Esempio n. 1
0
        protected override void Load(ContainerBuilder builder)
        {
            var sessionFactory = OWDatabaseConfiguration.Configure();

            builder.RegisterInstance(sessionFactory).AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(Assembly.Load("OW.Experts.Domain.NHibernate"))
            .Where(t => t.Name.StartsWith("NH"))
            .AsImplementedInterfaces()
            .InstancePerRequest();

            builder.RegisterGeneric(typeof(NHRepository <>))
            .As(typeof(IRepository <>))
            .Keyed("NHibernate", typeof(IRepository <>))
            .InstancePerRequest();

            builder.RegisterAssemblyTypes(Assembly.Load("OW.Experts.Domain.Linq"))
            .Where(t => t.Name.EndsWith("Repository"))
            .WithParameter(
                (pi, c) => pi.ParameterType.IsGenericType &&
                pi.ParameterType.GetGenericTypeDefinition() == typeof(IRepository <>),
                (pi, c) => c.ResolveKeyed(
                    "NHibernate",
                    typeof(IRepository <>).MakeGenericType(pi.ParameterType.GetGenericArguments())))
            .AsImplementedInterfaces()
            .InstancePerRequest();

            builder.RegisterGeneric(typeof(GetNotionsTypesQuery <>))
            .As(typeof(IGetNotionTypesQuery <>))
            .InstancePerRequest();

            FetchableQueryableFactory.Current = new NHFetchableQueryableFactory();
        }
Esempio n. 2
0
        public static void Main()
        {
            var sessionFactory    = OWDatabaseConfiguration.Configure("thread_static");
            var unitOfWorkFactory = new NHUnitOfWorkFactory(sessionFactory);

            using (var unitOfWork = unitOfWorkFactory.Create()) {
                var notionRepo = new NHRepository <NotionType>(sessionFactory);
                notionRepo.AddOrUpdate(new NotionType(Constants.NotionType));
                notionRepo.AddOrUpdate(new NotionType(Constants.ActionType));

                var relationRepo = new NHRepository <RelationType>(sessionFactory);
                relationRepo.AddOrUpdate(new RelationType(Constants.AssociationType));
                relationRepo.AddOrUpdate(new RelationType(Constants.TaxonomyType));
                relationRepo.AddOrUpdate(new RelationType(Constants.MeronomyType));

                unitOfWork.Commit();
            }
        }