Skip to content

Instantly share code, notes, and snippets.

View mt89vein's full-sized avatar

Sultanov mt89vein

View GitHub Profile
@mt89vein
mt89vein / Program.cs
Last active June 20, 2024 19:23
Using System.Threading.Channels with prioritized sending notifications
using System.Threading.Channels;
var notificator = new SlackNotificator(); // should be singleton
await Task.Delay(10); // give some time to init reader
// send some notifications with priority (higher number - higher priority)
var items = new[]
{
notificator.SendAsync(new Notification(1)),
@mt89vein
mt89vein / ValueObject.cs
Created March 15, 2024 18:48
Value object base class example
public abstract class ValueObject : IEquatable<ValueObject>
{
public bool Equals(ValueObject? other)
{
if (ReferenceEquals(this, other))
{
return true;
}
return other is not null &&
@mt89vein
mt89vein / example.cs
Created November 25, 2020 08:41
Default interface implementation
public interface IMessageDto {} // базовый интерфейс для всех DTO, здесь пустой, но может иметь уникальный ид, время создания и т.п
public interface IRabbitMessage {} // интерфейс для нетипизированных сообщений, здесь пустой, но по задумке владеет информацией о том откуда сообщение получить (роуты, обменники)
public interface IRabbitMessage<T> : IRabbitMessage // типизированный вариант IRabbitMessage
where T : IMessageDto
{
}
// одна из конкретных реализаций, для примера
public class MetricsRabbitMessage : IRabbitMessage<MetricsDto> { }
@mt89vein
mt89vein / CookieHelper.cs
Last active August 28, 2024 13:08
A cookies helper class to easily read and set cookies on HttpRequest (Asp.Net Core)
/// <summary>
/// Вспомогательные методы для работы с <see cref="Cookie"/>.
/// </summary>
public static class CookiesHelper
{
#region Методы (public)
/// <summary>
/// Получить список куки, которые сервер хочет установить через Set-Cookie.
/// </summary>