public void GenerateOpenAsyncMethod(bool transaction = false) { var method = new ContainerGen(); var methodName = transaction ? "OpenTransactionAsync" : "OpenAsync"; method.Signature = "public static async void " + methodName + "(Action<UnitOfWork> action)"; method.Body.Add(new StatementGen( "await Task.Run(() =>", "{"), new StatementGen( "using (var scope = G.TContainer.CreateScope())")); var usingBody = new BodyGen(); usingBody.Add(new StatementGen("var context = new `context`();")); if (transaction) { usingBody.Add(new StatementGen("var transaction = context.Database.BeginTransaction();")); } usingBody.Add(new StatementGen( "scope.ManageResources(context" + (transaction ? ", transaction" : "") + ");", "action.Invoke(new UnitOfWork(scope, context" + (transaction ? ", transaction" : "") + "));")); method.Body.Add(usingBody); method.Body.Add(new StatementGen( "});")); ContextManagerBody.Add(method, new StatementGen("")); }
public void GenerateOpenGetMethod(bool transaction = false) { var method = new ContainerGen(); var methodName = transaction ? "OpenTransactionGet" : "OpenGet"; method.Signature = "public static T " + methodName + "<T>(Func<UnitOfWork, T> func)"; method.Body.Add(new StatementGen( "using (var scope = G.TContainer.CreateScope())")); var usingBody = new BodyGen(); usingBody.Add(new StatementGen("var context = new `context`();")); if (transaction) { usingBody.Add(new StatementGen("var transaction = context.Database.BeginTransaction();")); } usingBody.Add(new StatementGen( "scope.ManageResources(context" + (transaction ? ", transaction" : "") + ");", "var res = func.Invoke(new UnitOfWork(scope, context" + (transaction ? ", transaction" : "") + "));")); usingBody.Add(new StatementGen( "return res;")); method.Body.Add(usingBody); ContextManagerBody.Add(method, new StatementGen("")); }
public void GenerateExtensionNamespace() { ENamespace = new ContainerGen(); ENamespace.ResolveMapping = ResolveMapping; ENamespace.Signature = "namespace " + EInfo.Data.ProjectName + ".Models.Extensions"; ENamespaceBody = ENamespace.Body; }
public void GenerateUnitOfWork() { UnitOfWork = new ContainerGen(); UnitOfWork.Signature = "public partial class UnitOfWork : `context`, IUnitOfWork"; UnitOfWorkBody = UnitOfWork.Body; var s1 = new StatementGen( "public " + Container + " Scope { get; }", "public DbContext Context { get; }"); var c21 = new ContainerGen(); c21.Signature = "public UnitOfWork(" + Container + " scope) : base()"; c21.Body.Add(new StatementGen( "Scope = scope;", "Context = this;")); var c22 = new ContainerGen(); c22.Signature = "public UnitOfWork(" + Container + " scope, DbContextOptions<`context`> options) : base(options)"; c22.Body.Add(new StatementGen( "Scope = scope;", "Context = this;")); var method = Data.DIContainer == DIContainer.TContainer ? "Resolve" : "GetService"; var m3 = new ContainerGen(); m3.Signature = "public S Repository<S>() where S : class, IRepository"; m3.Body.Add(new StatementGen( "var repository = Scope." + method + "<S>();", "return repository;" )); var m4 = new ContainerGen(); m4.Signature = "public D Domain<D>() where D : BaseDomain"; m4.Body.Add(new StatementGen( "var domain = Scope." + method + "<D>();", "return domain;" )); var m6 = new ContainerGen(); m6.Signature = "public IDbContextTransaction BeginTransaction()"; m6.Body.Add(new StatementGen( "var trans = this.Database.BeginTransaction();", "return trans;")); UnitOfWorkBody.Add( c21, new StatementGen(""), c22, new StatementGen(""), s1, new StatementGen(""), m3, new StatementGen(""), m4, new StatementGen(""), m6, new StatementGen("") ); NamespaceBody.Add(UnitOfWork); }
public void GenerateBaseDomain() { BaseDomain = new ContainerGen(); BaseDomain.Signature = "public abstract partial class BaseDomain";/*<E, VM, K, S> : IBaseDomain<E, VM, K> where S: class, IBaseService<E, VM, K> where E: class, IBaseEntity<VM> where VM: class";*/ BaseDomainBody = BaseDomain.Body; NamespaceBody.Add(BaseDomain); }
public void GenerateContextManager() { ContextManager = new ContainerGen(); ContextManager.Signature = "public partial class ContextManager"; ContextManagerBody = ContextManager.Body; NamespaceBody.Add(ContextManager); }
public void GenerateNamespace() { Namespace = new ContainerGen(); Namespace.Signature = "namespace " + Data.ProjectName + ".Managers"; NamespaceBody = Namespace.Body; Content = Namespace; }
public void GenerateIEntityService() { IEntityService = new ContainerGen(); IEntityService.Signature = "public partial interface I`entity`Service : IBaseService<`entity`, `entityPK`>"; IEntityServiceBody = IEntityService.Body; NamespaceBody.Add(IEntityService, new StatementGen("")); }
public void GenerateNamespace() { Namespace = new ContainerGen(); Namespace.Signature = "namespace " + Data.ProjectName + ".Models.Repositories"; NamespaceBody = Namespace.Body; Content = Namespace; }
public void GenerateVMClass() { VMClass = new ContainerGen(); VMClass.Signature = "public partial class `entityVM`: BaseViewModel<`entity`>"; VMClassBody = VMClass.Body; NamespaceBody.Add(VMClass); }
public void GenerateUpdateVMClass() { UpdateVMClass = new ContainerGen(); UpdateVMClass.Signature = "public partial class Update`entityVM`: BaseUpdateServiceModel<Update`entityVM`, `entity`>"; UpdateVMClassBody = UpdateVMClass.Body; NamespaceBody.Add(UpdateVMClass); }
public void GenerateVMClass() { VMClass = new ContainerGen(); VMClass.Signature = "public partial class `entityVM`: BaseServiceModel<`entity`>"; VMClassBody = VMClass.Body; NamespaceBody.Add(VMClass, new StatementGen("")); }
public void GenerateIEntityRepository() { IEntityRepository = new ContainerGen(); IEntityRepository.Signature = "public partial interface I`entity`Repository : IBaseRepository<`entity`, `entityPK`>"; IEntityRepositoryBody = IEntityRepository.Body; NamespaceBody.Add(IEntityRepository, new StatementGen("")); }
public void GenerateEntityExtension() { EntityExtension = new ContainerGen(); EntityExtension.Signature = "public partial class `entity` : BaseEntity"; EntityExtensionBody = EntityExtension.Body; NamespaceBody.Add(EntityExtension); }
public void GenerateNamespace() { Namespace = new ContainerGen(); Namespace.Signature = "namespace " + Data.ContextNamespace; NamespaceBody = Namespace.Body; Content = Namespace; }
private void GenerateNamespace() { Namespace = new ContainerGen(); Namespace.Signature = "namespace " + Data.ProjectName + ".Global"; NamespaceBody = Namespace.Body; Content = Namespace; }
public void GenerateBaseEntityExtension() { BaseEntityExtension = new ContainerGen(); BaseEntityExtension.Signature = "public partial class `entity` : BaseEntity"; BaseEntityExtensionBody = BaseEntityExtension.Body; NamespaceBody.Add(BaseEntityExtension, new StatementGen("")); }
public void GenerateBaseDomain() { BaseDomain = new ContainerGen(); BaseDomain.Signature = "public abstract partial class BaseDomain"; BaseDomainBody = BaseDomain.Body; NamespaceBody.Add(BaseDomain); }
public void GenerateNamespace() { Namespace = new ContainerGen(); Namespace.Signature = "namespace " + EInfo.Data.ProjectName + ".ViewModels"; NamespaceBody = Namespace.Body; Content = Namespace; }
public void GenerateEntityService() { EntityService = new ContainerGen(); EntityService.Signature = "public partial class `entity`Service : BaseService<`entity`, `entityPK`>, I`entity`Service"; EntityServiceBody = EntityService.Body; NamespaceBody.Add(EntityService); }
public void GenerateEntityRepository() { EntityRepository = new ContainerGen(); EntityRepository.Signature = "public partial class `entity`Repository : BaseRepository<`entity`, `entityPK`>, I`entity`Repository"; EntityRepositoryBody = EntityRepository.Body; NamespaceBody.Add(EntityRepository); }
public void GenerateBaseRepository() { BaseRepository = new ContainerGen(); BaseRepository.Signature = "public abstract partial class BaseRepository<E, K> : IBaseRepository<E, K> where E : class"; BaseRepositoryBody = BaseRepository.Body; NamespaceBody.Add(BaseRepository); }
public void GenerateBaseService() { BaseService = new ContainerGen(); BaseService.Signature = "public abstract partial class BaseService<E, K> : " + (Data.ServicePool ? "Resource, " : "") + "IBaseService<E, K>"; BaseServiceBody = BaseService.Body; NamespaceBody.Add(BaseService); }
public void GenerateIBaseRepository() { var IRepository = new ContainerGen(); IRepository.Signature = "public partial interface IRepository: IReusable"; NamespaceBody.Add(IRepository); IBaseRepository = new ContainerGen(); IBaseRepository.Signature = "public partial interface IBaseRepository<E, K> : IRepository"; IBaseRepositoryBody = IBaseRepository.Body; IBaseRepositoryBody.Add( new StatementGen( //"bool AutoSave { get; set; }", "int SaveChanges();", "Task<int> SaveChangesAsync();", "", "E Add(E entity);", //"Task<E> AddAsync(E entity);", "E Update(E entity);", //"Task <E> UpdateAsync(E entity);", "E Remove(E entity);", //"Task<E> RemoveAsync(E entity);", "E Remove(K key);", "IEnumerable<E> RemoveIf(Expression<Func<E, bool>> expr);", "IEnumerable<E> RemoveRange(IEnumerable<E> list);", //"Task<E> RemoveAsync(K key);", "E FindById(K key);", "Task<E> FindByIdAsync(K key);", "E FindActiveById(K key);", "Task<E> FindActiveByIdAsync(K key);", "E FindByIdInclude<TProperty>(K key, params Expression<Func<E, TProperty>>[] members);", "Task<E> FindByIdIncludeAsync<TProperty>(K key, params Expression<Func<E, TProperty>>[] members);", "E Activate(E entity);", "E Activate(K key);", "E Deactivate(E entity);", "E Deactivate(K key);", "IQueryable<E> GetActive();", "IQueryable<E> GetActive(Expression<Func<E, bool>> expr);", "E FirstOrDefault();", "E FirstOrDefault(Expression<Func<E, bool>> expr);", "Task<E> FirstOrDefaultAsync();", "Task<E> FirstOrDefaultAsync(Expression<Func<E, bool>> expr);", "E SingleOrDefault(Expression<Func<E, bool>> expr);", "Task<E> SingleOrDefaultAsync(Expression<Func<E, bool>> expr);", "DbRawSqlQuery<E> SqlQuery(string sql, params object[] parameters);", "DbRawSqlQuery<T> SqlQuery<T>(string sql, params object[] parameters);" )); NamespaceBody.Add(IBaseRepository, new StatementGen("")); }
private void GenerateGlobal() { GlobalClass = new ContainerGen(); GlobalClass.Signature = "public static partial class G"; GlobalClassBody = GlobalClass.Body; GlobalClassBody.Add( new StatementGen( "public static IMapper Mapper;", "public static ITContainer TContainer;", "private static ITContainerBuilder Builder = new TContainerBuilder();" )); NamespaceBody.Add(GlobalClass); }
public void GenerateIEntityRepository() { IEntityRepository = new ContainerGen(); IEntityRepository.Signature = "public partial interface I`entity`Repository : IBaseRepository<`entity`, `entityPK`>"; IEntityRepositoryBody = IEntityRepository.Body; if (EInfo.Activable) { IEntityRepositoryBody.Add( new StatementGen("`entity` FindActiveById(`entityPK` key);"), new StatementGen("Task<`entity`> FindActiveByIdAsync(`entityPK` key);"), new StatementGen("IQueryable<`entity`> GetActive();"), new StatementGen("IQueryable<`entity`> GetActive(Expression<Func<`entity`, bool>> expr);") ); } NamespaceBody.Add(IEntityRepository, new StatementGen("")); }
public void GenerateIBaseService() { var IService = new ContainerGen(); IService.Signature = "public partial interface IService" + (Data.ServicePool ? ": IResource" : ""); NamespaceBody.Add(IService); IBaseService = new ContainerGen(); IBaseService.Signature = "public partial interface IBaseService<E, K> : IService"; IBaseServiceBody = IBaseService.Body; IBaseServiceBody.Add( new StatementGen( //"bool AutoSave { get; set; }", "int SaveChanges();", "Task<int> SaveChangesAsync();", "", "E Add(E entity);", //"Task<E> AddAsync(E entity);", "E Update(E entity);", //"Task<E> UpdateAsync(E entity);", "E Remove(E entity);", //"Task<E> RemoveAsync(E entity);", "E Remove(K key);", "IEnumerable<E> RemoveIf(Expression<Func<E, bool>> expr);", "IEnumerable<E> RemoveRange(IEnumerable<E> list);", //"Task<E> RemoveAsync(K key);", "E FindById(K key);", "Task<E> FindByIdAsync(K key);", "E Activate(E entity);", "E Activate(K key);", "E Deactivate(E entity);", "E Deactivate(K key);", "IQueryable<E> GetActive();", "IQueryable<E> GetActive(Expression<Func<E, bool>> expr);", "E FirstOrDefault();", "E FirstOrDefault(Expression<Func<E, bool>> expr);", "Task<E> FirstOrDefaultAsync();", "Task<E> FirstOrDefaultAsync(Expression<Func<E, bool>> expr);" )); NamespaceBody.Add(IBaseService, new StatementGen("")); }
public void GenerateIBaseRepository() { var IRepository = new ContainerGen(); IRepository.Signature = "public partial interface IRepository"; NamespaceBody.Add(IRepository); IBaseRepository = new ContainerGen(); IBaseRepository.Signature = "public partial interface IBaseRepository<E, K> : IRepository where E : class"; IBaseRepositoryBody = IBaseRepository.Body; IBaseRepositoryBody.Add( new StatementGen( "int SaveChanges();", "Task<int> SaveChangesAsync();", "", "void Reload(E entity);", "EntityEntry<E> Create(E entity);", "void CreateRange(IEnumerable<E> entities);", "EntityEntry<E> Update(E entity);", "void UpdateRange(IEnumerable<E> entities);", "EntityEntry<E> Update(E entity, Action<E> patchAction);", "EntityEntry<E> Attach(E entity);", "EntityEntry<E> Remove(E entity);", "EntityEntry<E> Remove(K key);", "void RemoveIf(Expression<Func<E, bool>> expr);", "void RemoveRange(IEnumerable<E> list);", "E FindById(K key);", "Task<E> FindByIdAsync(K key);", "IQueryable<E> AsNoTracking();", "DbSet<E> Get();", "IQueryable<E> Get(Expression<Func<E, bool>> expr);", "E FirstOrDefault();", "E FirstOrDefault(Expression<Func<E, bool>> expr);", "Task<E> FirstOrDefaultAsync();", "Task<E> FirstOrDefaultAsync(Expression<Func<E, bool>> expr);", "E SingleOrDefault(Expression<Func<E, bool>> expr);", "Task<E> SingleOrDefaultAsync(Expression<Func<E, bool>> expr);" )); NamespaceBody.Add(IBaseRepository, new StatementGen("")); }
public void GenerateEntityPKClass() { if (EInfo.PKPropMapping.Count > 1) { EntityPKClass = new ContainerGen(); EntityPKClass.Signature = "public partial class `entityPK`"; EntityPKClassBody = EntityPKClass.Body; var statements = new StatementGen(); foreach (var kvp in EInfo.PKPropMapping) { var propName = kvp.Key; var propType = kvp.Value; statements.Add("public " + propType + " " + propName + " { get; set; }"); } EntityPKClassBody.Add(statements); NamespaceBody.Add(EntityPKClass, new StatementGen("")); } }
public void GenerateGeneralExtension() { GeneralExtension = new ContainerGen(); GeneralExtension.Signature = "public static partial class GeneralUtils"; GeneralExtensionBody = GeneralExtension.Body; var m1 = new ContainerGen(); m1.Signature = "public static List<VM> ToListVM<E, VM>(this IEnumerable<E> list) where E: IBaseEntity"; m1.Body.Add(new StatementGen("return list.Select(e => e.To<VM>()).ToList();")); var m2 = new ContainerGen(); m2.Signature = "public static List<E> ToListEntities<VM, E>(this IEnumerable<VM> list) where VM: IViewModel"; m2.Body.Add(new StatementGen("return list.Select(vm => vm.To<E>()).ToList();")); GeneralExtensionBody.Add( m1, new StatementGen(""), m2, new StatementGen("")); NamespaceBody.Add(GeneralExtension); }