コード例 #1
0
        public IModelConfiguration <TModel> ForMember <TProperty>(Expression <Func <TModel, TProperty> > propExpression, Action <IMemberConfiguration <TModel, TProperty> > action)
        {
            var propName = propExpression.GetFullPropertyName();
            var propInfo = ModelType.GetProperty(propName);

            if (propInfo == null)
            {
                throw new NullReferenceException(string.Format("Type '{0}' does not contain a property with name '{1}'.", ModelType, propName));
            }

            IMemberConfiguration memberConfiguration;

            if (MemberConfigurations.ContainsKey(propName))
            {
                memberConfiguration = MemberConfigurations[propName];
            }
            else
            {
                memberConfiguration = new MemberConfiguration <TModel, TProperty>(propInfo);
                BreezeConfigurator.OnSerializationMemberRuleCreated(memberConfiguration);
                MemberConfigurations[propName] = memberConfiguration;
            }

            if (action != null)
            {
                action((IMemberConfiguration <TModel, TProperty>)memberConfiguration);
            }

            return(this);
        }
コード例 #2
0
        public static void AddBreeze(this Container container, Action <BreezeOptions> action = null)
        {
            var options            = new BreezeOptions();
            var registeredServices = new HashSet <Type>(container.GetCurrentRegistrations().Select(o => o.ServiceType));

            container.TryRegisterSingleton <ISyntheticPropertyNameConvention, DefaultSyntheticPropertyNameConvention>(registeredServices);
            container.TryRegisterSingleton <INHibernateClassMetadataProvider, DefaultNHibernateClassMetadataProvider>(registeredServices);
            container.TryRegisterSingleton <IPropertyValidatorsProvider, FluentValidationPropertyValidatorsProvider>(registeredServices);
            container.TryRegisterSingleton <IJsonSerializerSettingsProvider, BreezeJsonSerializerSettingsProvider>(registeredServices);
            container.TryRegisterSingleton <IEntityQueryExecutor, DefaultEntityQueryExecutor>(registeredServices);
            container.TryRegisterSingleton <ILazyLoadGuardProvider, DefaultLazyLoadGuardProvider>(registeredServices);
            container.TryRegisterSingleton <IEntityMetadataProvider, EntityMetadataProvider>(registeredServices);
            container.TryRegisterSingleton <IClientModelMetadataProvider, ClientModelMetadataProvider>(registeredServices);
            container.TryRegisterSingleton <IProxyInitializer, ProxyInitializer>(registeredServices);
            container.TryRegisterSingleton <IEntityBatchFetcherFactory, EntityBatchFetcherFactory>(registeredServices);
            container.TryRegisterSingleton <IModelSaveValidatorProvider, DefaultModelSaveValidatorProvider>(registeredServices);
            container.TryRegisterSingleton <ITypeMembersProvider, DefaultTypeMembersProvider>(registeredServices);
            container.TryRegisterSingleton <IDataTypeProvider, DefaultDataTypeProvider>(registeredServices);
            container.TryRegisterSingleton <ISaveWorkStateFactory, SaveWorkStateFactory>(registeredServices);
            container.TryRegisterSingleton <BreezeContractResolver>(registeredServices);
            container.TryRegisterSingleton <IBreezeConfigurator>(() => {
                var configurator = new BreezeConfigurator(container.GetInstance <ITypeMembersProvider>());
                Configure(configurator);
                options.BreezeConfigurator?.Invoke(configurator);

                return(configurator);
            }, registeredServices);
            container.TryRegisterSingleton(() => {
                var builder = container.GetInstance <BreezeMetadataBuilder>()
                              .WithOrphanDeleteEnabled()
                              .WithPluralizeFunction(name => name.Pluralize());
                options.MetadataConfigurator?.Invoke(builder);

                return(builder.Build());
            }, registeredServices);

            container.TryRegisterScoped <EntityUpdater>(registeredServices);
            container.TryRegisterScoped <PersistenceManager>(registeredServices);
            container.TryRegisterScoped <ISessionProvider>(() => new DefaultSessionProvider(type => container.GetInstance <ISession>()), registeredServices);

            container.TryRegisterTransient <BreezeMetadataBuilder>(registeredServices);

            action?.Invoke(options);
        }
コード例 #3
0
        public IModelConfiguration <TModel> AddMember <TProperty>(string serializedName, Action <ICustomMemberConfiguration <TModel, TProperty> > action)
        {
            IMemberConfiguration memberConfiguration;

            if (MemberConfigurations.ContainsKey(serializedName))
            {
                memberConfiguration = MemberConfigurations[serializedName];
            }
            else
            {
                memberConfiguration = new MemberConfiguration <TModel, TProperty>(serializedName, typeof(TProperty), typeof(TModel));
                BreezeConfigurator.OnSerializationMemberRuleCreated(memberConfiguration);
                MemberConfigurations[serializedName] = memberConfiguration;
            }

            action?.Invoke((ICustomMemberConfiguration <TModel, TProperty>)memberConfiguration);

            return(this);
        }