/// <summary> /// Get context object associated with the service of the specified type. /// </summary> /// <param name="typeFullName"></param> /// <returns></returns> public IActionContext GetContext(string typeFullName) { EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName); IActionContext actionContext = Activator.CreateInstance(ctx.ActionContextType) as IActionContext; return(actionContext); }
/// <summary> /// Get a new entity of the specified type. /// </summary> /// <param name="typeFullName"></param> /// <returns></returns> public object GetEntity(string typeFullName) { EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName); object entity = Activator.CreateInstance(ctx.EntityType); return(entity); }
/// <summary> /// Get the entity Service(supporting CRUD operations). /// </summary> /// <param name="typeFullName"></param> /// <returns></returns> public object GetService(string typeFullName) { EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName); string serviceName = ctx.Name + EntityRegistrationConstants.SuffixService; object obj = Ioc.GetObject <object>(serviceName); return(obj); }
/// <summary> /// Get an object from the IocContainer using the type's full name and a suffix. /// </summary> /// <param name="typeFullName"></param> /// <param name="suffix"></param> /// <returns></returns> public object GetObject(string typeFullName, string suffix) { EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName); string entryName = ctx.Name + suffix; object obj = Ioc.GetObject <object>(entryName); return(obj); }
private object InvokeAction(EntityServiceContext ctx, string methodName) { // Create the appropriate type of actioncontext for the specific entity being managed. // And then set it's errors and messages to the calling context so the errors / messages // can be available to the caller. IActionContext actionContext = EntityRegistration.GetContext(ctx.EntityName); actionContext.CombineMessageErrors = true; actionContext.Item = ctx.Item; actionContext.Id = ctx.Id; actionContext.Errors = ctx.Errors; object service = EntityRegistration.GetService(ctx.EntityName); object result = ReflectionUtils.InvokeMethod(service, methodName, new object[] { actionContext }); return(result); }
/// <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 Register <T>(Func <IEntityService <T> > serviceCreator, Func <IEntityRepository <T> > repoCreator, Func <IEntityValidator <T> > validatorCreator, bool configureRepository) { EntityRegistrationContext ctx = new EntityRegistrationContext(); ctx.EntityType = typeof(T); ctx.Name = typeof(T).FullName; ctx.IsSingletonService = false; ctx.IsSingletonRepository = false; ctx.IsRepositoryConfigurationRequired = configureRepository; ctx.FactoryMethodForService = new Func <object>(() => serviceCreator()); ctx.CreationMethod = EntityCreationType.Factory; ctx.ActionContextType = typeof(ActionContext <T>); if (repoCreator != null) { ctx.FactoryMethodForRepository = new Func <object>(() => repoCreator()); } if (validatorCreator != null) { ctx.FactoryMethodForValidator = new Func <object>(() => validatorCreator()); } EntityRegistration.Register(ctx); }