예제 #1
0
 /// <summary>
 /// Initializes a new instance of the CollectionViewModelBase class.
 /// </summary>
 /// <param name="unitOfWorkFactory">A factory used to create a unit of work instance.</param>
 /// <param name="getRepositoryFunc">A function that returns a repository representing entities of the given type.</param>
 /// <param name="projection">A LINQ function used to customize a query for entities. The parameter, for example, can be used for sorting data and/or for projecting data to a custom type that does not match the repository entity type.</param>
 /// <param name="newEntityInitializer">A function to initialize a new entity. This parameter is used in the detail collection view models when creating a single object view model for a new entity.</param>
 /// <param name="canCreateNewEntity">A function that is called before an attempt to create a new entity is made. This parameter is used together with the newEntityInitializer parameter.</param>
 /// <param name="ignoreSelectEntityMessage">A parameter used to specify whether the selected entity should be managed by PeekCollectionViewModel.</param>
 protected CollectionViewModelBase(
     IUnitOfWorkFactory <TUnitOfWork> unitOfWorkFactory,
     Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
     Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection,
     Action <TEntity> newEntityInitializer,
     Func <bool> canCreateNewEntity,
     bool ignoreSelectEntityMessage
     ) : base(unitOfWorkFactory, getRepositoryFunc, projection)
 {
     RepositoryExtensions.VerifyProjection(CreateRepository(), projection);
     this.newEntityInitializer      = newEntityInitializer;
     this.canCreateNewEntity        = canCreateNewEntity;
     this.ignoreSelectEntityMessage = ignoreSelectEntityMessage;
     if (!this.IsInDesignMode())
     {
         RegisterSelectEntityMessage();
     }
 }
예제 #2
0
        protected InstantFeedbackCollectionViewModelBase(
            IUnitOfWorkFactory <TUnitOfWork> unitOfWorkFactory,
            Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
            Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection,
            Func <bool> canCreateNewEntity = null)
        {
            this.unitOfWorkFactory  = unitOfWorkFactory;
            this.canCreateNewEntity = canCreateNewEntity;
            this.getRepositoryFunc  = getRepositoryFunc;
            this.Projection         = projection;
            this.helperRepository   = CreateRepository();

            RepositoryExtensions.VerifyProjection(helperRepository, projection);

            this.source   = unitOfWorkFactory.CreateInstantFeedbackSource(getRepositoryFunc, Projection);
            this.Entities = InstantFeedbackSourceViewModel.Create(() => helperRepository.Count(), source);

            if (!this.IsInDesignMode())
            {
                OnInitializeInRuntime();
            }
        }