/// <summary> /// Get the entity Service(supporting CRUD operations). /// </summary> /// <param name="typeFullName"></param> /// <returns></returns> public static object GetService(string typeFullName) { EntityRegistrationContext ctx = _managableEntities[typeFullName]; // Singleton. if (ctx.IsSingletonService) { return(ctx.Service); } object service = null; object repository = null; if (ctx.CreationMethod == EntityCreationType.Factory) { service = ctx.FactoryMethodForService(); if (ctx.FactoryMethodForRepository != null) { repository = ctx.FactoryMethodForRepository(); } if (repository != null && ctx.IsRepositoryConfigurationRequired) { RepositoryConfigurator.Configure((IRepositoryConfigurable)repository); } } else { service = _entityRegistrarIoc.GetService(typeFullName); } return(service); }
/// <summary> /// Registers the specified CTX for creating the components /// necessary for the DomainModel ActiveRecord. /// </summary> /// <param name="ctx">The CTX.</param> public static void Register(EntityRegistrationContext ctx) { if (!_managableEntities.ContainsKey(ctx.EntityType.FullName)) { _managableEntities.Add(ctx.EntityType.FullName, ctx); _managableEntitiesList.Add(ctx.EntityType.FullName); } // Overwrite else { _managableEntities[ctx.EntityType.FullName] = ctx; } // Register. if (ctx.IsRepositoryConfigurationRequired && ctx.IsSingletonRepository) { RepositoryConfigurator.Configure((IRepositoryConfigurable)ctx.Repository); } }
/// <summary> /// Register a singleton service/repository for the entity specified by T. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="service"></param> /// <param name="configureRepository"></param> public static void Register <T>(IEntityService <T> service, bool configureRepository) { EntityRegistrationContext ctx = new EntityRegistrationContext(); ctx.EntityType = typeof(T); ctx.Name = typeof(T).FullName; ctx.IsSingletonService = true; ctx.IsSingletonRepository = true; ctx.Service = service; ctx.Repository = service.Repository; ctx.IsRepositoryConfigurationRequired = configureRepository; ctx.CreationMethod = EntityCreationType.Factory; ctx.ActionContextType = typeof(ActionContext <T>); if (ctx.IsRepositoryConfigurationRequired) { RepositoryConfigurator.Configure(service.Repository); } Register(ctx); }