public void should_override_the_default_predicate() { IsCandidateForRepositoryDelegate typeIsAlwaysTrue = delegate { return(true); }; NHibernateUnitOfWorkFacilityConfig config = CreateSUT().RegisterEntitiesWhere(typeIsAlwaysTrue); Assert.AreEqual(typeIsAlwaysTrue, config.IsCandidateForRepository); }
/// <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)) ); } } }
/// <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); }
/// <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); }
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; }
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; }
/// <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)) ); } } }
public NHibernateUnitOfWorkFacilityConfig RegisterEntitiesWhere(IsCandidateForRepositoryDelegate typeIsSpecifiedBy) { Guard.Against <ArgumentNullException>(typeIsSpecifiedBy == null, "Predicate cannot be null."); isCandidateForRepository = typeIsSpecifiedBy; return(this); }