This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CacheInterceptor : IInterceptor | |
{ | |
private readonly IDistributedCache _distributedCache; | |
public CacheInterceptor(IDistributedCache distributedCache) | |
{ | |
_distributedCache = distributedCache; | |
} | |
public void Intercept(IInvocation invocation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Method)] | |
public class CacheMethodAttribute : Attribute | |
{ | |
public CacheMethodAttribute(int secondsToCache = 10) | |
{ | |
SecondsToCache = secondsToCache; | |
} | |
public int SecondsToCache { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static byte[] ToByteArray(this Object obj) | |
{ | |
BinaryFormatter bf = new BinaryFormatter(); | |
using (var ms = new MemoryStream()) | |
{ | |
bf.Serialize(ms, obj); | |
return ms.ToArray(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ITestService | |
{ | |
Result GetName(Param1 param); | |
} | |
public class TestService : ITestService | |
{ | |
public TestService() | |
{ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add to di singleton | |
public class Worker | |
{ | |
private readonly ILogger<Worker> _logger; | |
private readonly IServiceProvider _serviceProvider; | |
private readonly ActionBlock<SmsReq> _action; | |
public Worker(IServiceProvider serviceProvider, ILogger<Worker> logger) | |
{ | |
_serviceProvider = serviceProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SmsReq | |
{ | |
// add body, encoding, receipt, from | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISmsSender | |
{ | |
Task Send(SmsReq model); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add to di singleton | |
public class Workers | |
{ | |
private ConcurrentBag<IDataflowBlock> Actions { get; set; } = new ConcurrentBag<IDataflowBlock>(); | |
public ActionBlock<TInput> AddWork<TInput>(Func<TInput, Task> work) where TInput : class, new() | |
{ | |
var action = new ActionBlock<TInput>(work); | |
Actions.Add(action); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//fill object | |
var smsContext = new SmsReq(); | |
var action = _workers.AddWork<SmsReq>(SendSms); | |
action.Post(smsContext); | |
private async Task SendSms(SmsReq smsReq) | |
{ | |
try |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChannelService<TMessage> where TMessage : class, new() | |
{ | |
private readonly Channel<TMessage> _serviceChannel; | |
public ChannelService() | |
{ | |
_serviceChannel = Channel.CreateBounded<TMessage>(new BoundedChannelOptions(5000) | |
{ | |
SingleReader = false, | |
SingleWriter = false, |
OlderNewer