/// <summary> /// Initialize the service, repository creators. /// </summary> /// <param name="serviceCreator">The service creator.</param> /// <param name="repoCreator">The repository creator.</param> /// <param name="configureRepository">Whether or not to configure the reposiory.</param> public static void Init(Func <IEntityService <T> > serviceCreator, Func <IRepository <T> > repoCreator, Func <IEntityValidator> validatorCreator, IEntitySettings settings, IEntityResources resources, bool configureRepository, string connId) { EntityRegistration.Register <T>(serviceCreator, repoCreator, validatorCreator, settings, resources, configureRepository, connId); var ctx = EntityRegistration.GetRegistrationContext(typeof(T).FullName); MethodInfo callback = typeof(T).GetMethod("OnAfterInit"); if (callback != null) { callback.Invoke(null, null); } // Setup flags for entity life-cycle callbacks. ctx.HasOnBeforeValidate = HasMethod("OnBeforeValidate"); ctx.HasOnBeforeValidateCreate = HasMethod("OnBeforeValidateCreate"); ctx.HasOnBeforeValidateUpdate = HasMethod("OnBeforeValidateUpdate"); ctx.HasOnBeforeCreate = HasMethod("OnBeforeCreate"); ctx.HasOnBeforeUpdate = HasMethod("OnBeforeUpdate"); ctx.HasOnBeforeSave = HasMethod("OnBeforeSave"); ctx.HasOnBeforeDelete = HasMethod("OnBeforeDelete"); ctx.HasOnAfterValidate = HasMethod("OnAfterValidate"); ctx.HasOnAfterValidateCreate = HasMethod("OnAfterValidateCreate"); ctx.HasOnAfterValidateUpdate = HasMethod("OnAfterValidateUpdate"); ctx.HasOnAfterCreate = HasMethod("OnAfterCreate"); ctx.HasOnAfterUpdate = HasMethod("OnAfterUpdate"); ctx.HasOnAfterSave = HasMethod("OnAfterSave"); ctx.HasOnAfterDelete = HasMethod("OnAfterDelete"); }
/// <summary> /// Initialize the service, repository creators. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceCreator">The service creator.</param> /// <param name="repoCreator">The repository creator.</param> /// <param name="validatorCreator">The validator creator.</param> /// <param name="settings">The settings.</param> /// <param name="resources">The resources.</param> /// <param name="configureRepository">Whether or not to configure the reposiory.</param> /// <param name="connectionId">The connection id.</param> public static void Register <T>(Func <IEntityService <T> > serviceCreator, Func <IRepository <T> > repoCreator, Func <IEntityValidator> validatorCreator, IEntitySettings settings, IEntityResources resources, bool configureRepository, string connectionId) { EntityRegistrationContext ctx = new EntityRegistrationContext(); ctx.EntityType = typeof(T); ctx.Name = typeof(T).FullName; ctx.IsSingletonService = false; ctx.IsSingletonRepository = false; ctx.IsRepositoryConfigurationRequired = configureRepository; ctx.CreationMethod = EntityCreationType.Factory; ctx.ActionContextType = typeof(ActionContext <T>); ctx.Settings = settings; ctx.Resources = resources; ctx.FactoryMethodForService = new Func <object>(() => serviceCreator()); ctx.ConnectionId = connectionId; if (repoCreator != null) { ctx.FactoryMethodForRepository = new Func <object>(() => repoCreator()); } else if (serviceCreator != null) { ctx.Repository = serviceCreator().Repository; } if (validatorCreator != null) { ctx.FactoryMethodForValidator = new Func <object>(() => validatorCreator()); } EntityRegistration.Register(ctx); }
/// <summary> /// Initialize the service, repository for the model T. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repoCreator">The repository creator.</param> /// <param name="validatorCreator">The validator creator.</param> /// <param name="settings">The settings.</param> /// <param name="resources">The resources.</param> /// <param name="configureRepository">Whether or not to configure the reposiory.</param> /// <param name="connId">The conn id.</param> public static void Register <T>(Func <IRepository <T> > repoCreator, Func <IEntityValidator> validatorCreator, IEntitySettings settings, IEntityResources resources, bool configureRepository, string connId) where T : IEntity { Register <T>(() => new EntityService <T>(), repoCreator, validatorCreator, settings, resources, configureRepository, connId); }