Exemplo n.º 1
0
        /// <summary> Create child repository and set this as parent </summary>
        public virtual TRepository GetChildRepository <TRepository>() where TRepository : IBaseRepository
        {
            TRepository repo = HttpContext.RequestServices.GetRequiredService <TRepository>();

            if (repo != null)
            {
                repo.Parent = this;
            }
            else
            {
                var errorMessage = $"Repository {typeof(TRepository).Name} not registred";
                throw new InvalidOperationException(GeneralContext.GetApiMessageInfo(errorMessage, EventLevel.Critical));
            }
            return(repo);
        }
Exemplo n.º 2
0
        /// <summary> Create child service and set this as parent </summary>
        public virtual TService GetChildService <TService>() where TService : IBaseService
        {
            TService service = default;

            try
            {
                service        = HttpContext.RequestServices.GetRequiredService <TService>();
                service.Parent = this;
                service.IsTransactionEnabled = this.IsTransactionEnabled;
            }
            catch (Exception ex)
            {
                var errorMessage = $"Serice {typeof(TService).Name} not registred {ex.GetApiMessageInfo()}";
                throw new InvalidOperationException(GeneralContext.GetApiMessageInfo(errorMessage, EventLevel.Critical));
            }
            return(service);
        }