-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBusinessLayerContext.cs
63 lines (55 loc) · 1.79 KB
/
BusinessLayerContext.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Havit.Business.Caching;
using Havit.Diagnostics.Contracts;
using Havit.Services.Caching;
namespace Havit.Business;
/// <summary>
/// Ambientní kontext pro Business Layer.
/// </summary>
public static class BusinessLayerContext
{
/// <summary>
/// Služba pro práci s cache v Business Layer.
/// </summary>
public static IBusinessLayerCacheService BusinessLayerCacheService
{
get
{
if (_businessLayerCacheServiceFunc != null)
{
return _businessLayerCacheServiceFunc();
}
// zpětná kompatibilita
if (_defaultBusinessLayerCacheService == null)
{
#if NETFRAMEWORK
_defaultBusinessLayerCacheService = new DefaultBusinessLayerCacheService(new HttpRuntimeCacheService());
#else
_defaultBusinessLayerCacheService = new DefaultBusinessLayerCacheService(new ObjectCacheService(System.Runtime.Caching.MemoryCache.Default));
#endif
}
return _defaultBusinessLayerCacheService;
}
}
private static Func<IBusinessLayerCacheService> _businessLayerCacheServiceFunc;
private static IBusinessLayerCacheService _defaultBusinessLayerCacheService;
/// <summary>
/// Nastavuje služba pro práci s cache v Business Layer.
/// </summary>
public static void SetBusinessLayerCacheService(IBusinessLayerCacheService businessLayerCacheService)
{
SetBusinessLayerCacheService(() => businessLayerCacheService);
}
/// <summary>
/// Nastavuje služba pro práci s cache v Business Layer.
/// </summary>
public static void SetBusinessLayerCacheService(Func<IBusinessLayerCacheService> businessLayerCacheServiceFunc)
{
Contract.Requires<ArgumentNullException>(businessLayerCacheServiceFunc != null);
_businessLayerCacheServiceFunc = businessLayerCacheServiceFunc;
}
}