| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using Microsoft.Extensions.Logging;
- using Quadarax.Foundation.Core.Business.Interface;
- using Quadarax.Foundation.Core.Data.Interface.Domain;
- using Quadarax.Foundation.Core.Data.Interface.Entity;
- using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
- namespace Quadarax.Foundation.Core.Business
- {
- public abstract class AbstractService : IService
- {
- #region *** Properties ***
- protected ILogger<AbstractService> Log { get; }
- protected IContext CurrentContext { get; }
- protected ILoggerFactory LoggerFactory { get; }
- #endregion
- #region *** Constructors ***
- protected AbstractService(IContext currentContext, ILoggerFactory logger)
- {
- CurrentContext = currentContext ?? throw new ArgumentNullException(nameof(currentContext));
- if (logger == null)throw new ArgumentNullException(nameof(logger));
-
- Log = logger.CreateLogger<AbstractService>();
- LoggerFactory = logger;
- //if (currentContext == null)
- //{
- // var genericIdentity = new GenericIdentity("genericIdentity");
- // currentContext = new GenericPrincipal(genericIdentity, new string[] {});
- //}
- Log.LogTrace($"Service '{GetType().Name}' [Hash:{GetHashCode()}] initialized.");
- }
- #endregion
- #region *** Private Operations ***
- protected TResult TryCatchBlock<TResult>(Func<TResult> fnc) where TResult : ResultDto
- {
- if (fnc == null)
- return null;
- var result = Activator.CreateInstance<TResult>();
- try
- {
- result = fnc();
- }
- catch (Exception e)
- {
- result.AppendException(e);
- }
- return result;
- }
- protected TContext GetContext<TContext>() where TContext : IContext
- {
- return (TContext)CurrentContext;
- }
- #endregion
- #region *** Public Operations ***
- public IResult Test()
- {
- return new ResultPlain();
- }
- #endregion
- }
- }
|