Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Пишите правильный код

Calabonga Calabonga

💭
Пишите правильный код
View GitHub Profile
@Calabonga
Calabonga / BenchmarkTemplate.cs
Created December 22, 2022 01:01
Benchmarking with BenchmarkDotNet
View BenchmarkTemplate.cs
[RankColumn]
[HideColumns(new string[] { "Job" })]
[MemoryDiagnoser(false)]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net70)]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByMethod)]
public class Benchmark
{
// ... start from here
}
@Calabonga
Calabonga / JsonSerializerOptions Demo
Created September 3, 2022 03:44
JsonSerializerOptions
View JsonSerializerOptions Demo
var options = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
}
var json = JsonSerializer.Serialize(state, options);
@Calabonga
Calabonga / Program.cs
Last active November 24, 2022 02:37
Logger and configuration for Console Application
View Program.cs
/* required nugets
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
@Calabonga
Calabonga / Directory.Build.props
Created May 4, 2022 01:39
Visual Studio properties for all projects
View Directory.Build.props
<Project>
<PropertyGroup>
<!-- <LangVersion>latest</LangVersion> -->
<!--<LangVersion>preview</LangVersion>-->
<LangVersion>8</LangVersion>
</PropertyGroup>
</Project>
@Calabonga
Calabonga / xunit.runner.json
Last active April 29, 2022 03:21
xunit.runner.json
View xunit.runner.json
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
@Calabonga
Calabonga / TaskHelper.cs
Created April 20, 2022 08:24
Run and forget task C#
View TaskHelper.cs
public static class TaskHelper
{
/// <summary>
/// Runs a TPL Task fire-and-forget style, the right way - in the
/// background, separate from the current thread, with no risk
/// of it trying to rejoin the current thread.
/// </summary>
public static void RunBg(Func<Task> fn) => Task.Run(fn).ConfigureAwait(false);
/// <summary>
@Calabonga
Calabonga / AsyncHelper.cs
Last active April 20, 2022 04:17
AsyncHelper helps to start asynchronous method as synchronously
View AsyncHelper.cs
public static class AsyncHelpers
{
/// <summary>
/// Executes an async Task<T> method which has a void return value synchronously
/// </summary>
/// <param name="task">Task<T> method to execute</param>
public static void RunSync(Func<Task> task)
{
var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext();
View vertical-slice-architecture.md

Layered Architecture

flowchart TD
    subgraph FEATURES
        Presentation --> Application
        Application --> Domain
        Domain --> Infrastructure
        Infrastructure --> Database
 end
@Calabonga
Calabonga / TaskExtended.cs
Created June 22, 2021 03:08
Task extended version for catching all exceptions when all starts
View TaskExtended.cs
public class TaskExtended
{
public static async Task<IEnumerable<T>> WhenAll<T>(params Task<T>[] tasks)
{
var allTasks = Task.WhenAll(tasks);
try
{
return await allTasks;
}
View .editorconfig
root = true
# Remove the line below if you want to inherit .editorconfig settings from higher directories
[*.json]
indent_size = 4
indent_style = space
tab_width = 4
# C# files
[*.cs]