コード例 #1
0
        public void should_override_the_default_predicate()
        {
            IsCandidateForRepositoryDelegate   typeIsAlwaysTrue = delegate { return(true); };
            NHibernateUnitOfWorkFacilityConfig config           = CreateSUT().RegisterEntitiesWhere(typeIsAlwaysTrue);

            Assert.AreEqual(typeIsAlwaysTrue, config.IsCandidateForRepository);
        }
コード例 #2
0
        /// <summary>
        /// Registers the interfaces of the entities defined in the session factory in the kernel.
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        /// <param name="sessionFactory">The session factory.</param>
        /// <param name="repository">The repository type to map to <seealso cref="IRepository{T}"/>.</param>
        /// <param name="isCandidateForRepository">The is candidate for repository.</param>
        /// <remarks>
        /// The reason that we have the <paramref name="isCandidateForRepository"/> is to avoid registering services
        /// for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
        /// </remarks>
        public static void Register(
            IKernel kernel,
            ISessionFactory sessionFactory,
            Type repository,
            IsCandidateForRepositoryDelegate isCandidateForRepository
            )
        {
            if (ImplementsOpenIRepository(repository) == false)
            {
                throw new ArgumentException("Repository must be a type inheriting from IRepository<T>, and must be an open generic type. Sample: typeof(NHRepository<>).");
            }

            foreach (IClassMetadata meta in sessionFactory.GetAllClassMetadata().Values)
            {
                Type mappedClass = meta.GetMappedClass(EntityMode.Poco);
                if (mappedClass == null)
                {
                    continue;
                }
                foreach (Type interfaceType in mappedClass.GetInterfaces())
                {
                    if (isCandidateForRepository(interfaceType, mappedClass) == false)
                    {
                        continue;
                    }
                    kernel.Register(
                        Component.For(typeof(IRepository <>).MakeGenericType(interfaceType))
                        .ImplementedBy(repository.MakeGenericType(interfaceType))
                        .DependsOn(Property.ForKey("ConcreteType").Eq(mappedClass))
                        );
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Registers the interfaces of the entities defined in the session factory in the container.
 /// </summary>
 /// <param name="windsorContainer">The windsor container.</param>
 /// <param name="sessionFactory">The session factory.</param>
 /// <param name="repository">The repository type to map to <seealso cref="IRepository{T}"/>.</param>
 /// <param name="isCandidateForRepository">The is candidate for repository.</param>
 /// <remarks>
 /// The reason that we have the <paramref name="isCandidateForRepository"/> is to avoid registering services
 /// for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
 /// </remarks>
 public static void Register(
     IWindsorContainer windsorContainer,
     ISessionFactory sessionFactory,
     Type repository,
     IsCandidateForRepositoryDelegate isCandidateForRepository
     )
 {
     Register(windsorContainer.Kernel, sessionFactory, repository, isCandidateForRepository);
 }
コード例 #4
0
 /// <summary>
 /// Registers the interfaces of the entities defined in the session factory in the container.
 /// </summary>
 /// <param name="windsorContainer">The windsor container.</param>
 /// <param name="sessionFactory">The session factory.</param>
 /// <param name="repository">The repository type to map to <seealso cref="IRepository{T}"/>.</param>
 /// <param name="isCandidateForRepository">The is candidate for repository.</param>
 /// <remarks>
 /// The reason that we have the <paramref name="isCandidateForRepository"/> is to avoid registering services
 /// for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
 /// </remarks>
 public static void Register(
     IWindsorContainer windsorContainer,
     ISessionFactory sessionFactory,
     Type repository,
     IsCandidateForRepositoryDelegate isCandidateForRepository
     )
 {
     Register(windsorContainer.Kernel, sessionFactory, repository, isCandidateForRepository);
 }
コード例 #5
0
        public void Should_register_entities_to_the_repository()
        {
            IsCandidateForRepositoryDelegate   entityInThisAssembly = delegate(Type t, Type c) { return(t.Assembly == GetType().Assembly); };
            NHibernateUnitOfWorkFacilityConfig config = BuildFacilityConfiguration().RegisterEntitiesWhere(entityInThisAssembly);

            IoC.Container.AddFacility(facilityKey, new NHibernateUnitOfWorkFacility(config));

            using (UnitOfWork.Start())
                Assert.IsNotNull(Repository <IParent> .Create());
        }
 public EntitiesToRepositoriesInitializationAware(IsCandidateForRepositoryDelegate isCandidateForRepository)
 {
     this.isCandidateForRepository = isCandidateForRepository;
 }
コード例 #7
0
 public NHibernateUnitOfWorkFacilityConfig RegisterEntitiesWhere(IsCandidateForRepositoryDelegate typeIsSpecifiedBy)
 {
     Guard.Against<ArgumentNullException>(typeIsSpecifiedBy == null, "Predicate cannot be null.");
     isCandidateForRepository = typeIsSpecifiedBy;
     return this;
 }
 public EntitiesToRepositoriesInitializationAware(IsCandidateForRepositoryDelegate isCandidateForRepository)
 {
     this.isCandidateForRepository = isCandidateForRepository;
 }
コード例 #9
0
        /// <summary>
        /// Registers the interfaces of the entities defined in the session factory in the kernel.
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        /// <param name="sessionFactory">The session factory.</param>
        /// <param name="repository">The repository type to map to <seealso cref="IRepository{T}"/>.</param>
        /// <param name="isCandidateForRepository">The is candidate for repository.</param>
        /// <remarks>
        /// The reason that we have the <paramref name="isCandidateForRepository"/> is to avoid registering services
        /// for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
        /// </remarks>
        public static void Register(
            IKernel kernel,
            ISessionFactory sessionFactory,
            Type repository,
            IsCandidateForRepositoryDelegate isCandidateForRepository
            )
        {
            if (ImplementsOpenIRepository(repository) == false)
                throw new ArgumentException("Repository must be a type inheriting from IRepository<T>, and must be an open generic type. Sample: typeof(NHRepository<>).");

            foreach (IClassMetadata meta in sessionFactory.GetAllClassMetadata().Values)
            {
                Type mappedClass = meta.GetMappedClass(EntityMode.Poco);
                if (mappedClass == null)
                    continue;
                foreach (Type interfaceType in mappedClass.GetInterfaces())
                {
                    if (isCandidateForRepository(interfaceType, mappedClass) == false)
                        continue;
                    kernel.Register(
                        Component.For(typeof(IRepository<>).MakeGenericType(interfaceType))
                            .ImplementedBy(repository.MakeGenericType(interfaceType))
                            .DependsOn(Property.ForKey("ConcreteType").Eq(mappedClass))
                        );
                }
            }
        }
コード例 #10
0
 public NHibernateUnitOfWorkFacilityConfig RegisterEntitiesWhere(IsCandidateForRepositoryDelegate typeIsSpecifiedBy)
 {
     Guard.Against <ArgumentNullException>(typeIsSpecifiedBy == null, "Predicate cannot be null.");
     isCandidateForRepository = typeIsSpecifiedBy;
     return(this);
 }