-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnitOfWorkBase.cs
38 lines (34 loc) · 1.27 KB
/
UnitOfWorkBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
namespace Citolab.Persistence
{
/// <summary>
/// Base class for unit of work implementations.
/// </summary>
public abstract class UnitOfWorkBase : IUnitOfWork
{
public Guid? ActorId { get; set; }
protected readonly ILoggerFactory LoggerFactory;
protected readonly bool LogTime;
protected readonly IMemoryCache MemoryCache;
/// <summary>
/// </summary>
/// <param name="memoryCache"></param>
/// <param name="loggerFactory"></param>
/// <param name="options"></param>
protected UnitOfWorkBase(IMemoryCache memoryCache, ILoggerFactory loggerFactory,
ICollectionOptions options)
{
MemoryCache = memoryCache;
LoggerFactory = loggerFactory;
var logger = loggerFactory.CreateLogger(GetType());
if (!options.TimeLoggingEnabled) return;
logger.LogDebug(
"Time logging is enabled in appsettings: logging time with the LogTimeDecorator will be started.");
LogTime = true;
}
/// <inheritdoc />
public abstract ICollection<T> GetCollection<T>() where T : Model, new();
}
}