Skip to content

Commit

Permalink
Code cleanup, add serilog example
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Dec 16, 2024
1 parent 81506c0 commit 18eccab
Show file tree
Hide file tree
Showing 94 changed files with 477 additions and 161 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ dotnet run
- [Exposed roots via root arg](readme/exposed-roots-via-root-arg.md)
- [Exposed generic roots](readme/exposed-generic-roots.md)
- [Exposed generic roots with args](readme/exposed-generic-roots-with-args.md)
- [Serilog](readme/serilog.md)
### Applications
- Console
- [Schrödinger's cat](readme/Console.md)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/BaseAbstractContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract IAbstractContainer<TActualContainer> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default);
string? name = null);

public abstract T Resolve<T>() where T : class;

Expand Down
2 changes: 2 additions & 0 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#pragma warning disable CA1822
namespace Pure.DI.Benchmarks.Benchmarks;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using Model;

[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MemoryDiagnoser]
[SuppressMessage("Usage", "CA2263:Предпочитать универсальную перегрузку, если тип известен")]
public partial class Array : BenchmarkBase
{
private static void SetupDI() =>
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#pragma warning disable CA1822
namespace Pure.DI.Benchmarks.Benchmarks;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using Model;

[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MemoryDiagnoser]
[SuppressMessage("Usage", "CA2263:Предпочитать универсальную перегрузку, если тип известен")]
public partial class Enum : BenchmarkBase
{
private static void SetupDI() =>
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Func.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#pragma warning disable CA1822
namespace Pure.DI.Benchmarks.Benchmarks;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using Model;

[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MemoryDiagnoser]
[SuppressMessage("Usage", "CA2263:Предпочитать универсальную перегрузку, если тип известен")]
public partial class Func : BenchmarkBase
{
private static void SetupDI() =>
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#pragma warning disable CA1822
namespace Pure.DI.Benchmarks.Benchmarks;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using Model;

[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MemoryDiagnoser]
[SuppressMessage("Usage", "CA2263:Предпочитать универсальную перегрузку, если тип известен")]
public partial class Singleton : BenchmarkBase
{
private static void SetupDI() =>
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Transient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#pragma warning disable CA1822
namespace Pure.DI.Benchmarks.Benchmarks;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using Model;

[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MemoryDiagnoser]
[SuppressMessage("Usage", "CA2263:Предпочитать универсальную перегрузку, если тип известен")]
public partial class Transient : BenchmarkBase
{
private static void SetupDI() =>
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/Autofac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override IAbstractContainer<IContainer> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
var registration = _builder.RegisterType(implementationType).As(contractType);
switch (lifetime)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/CastleWindsor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override IAbstractContainer<WindsorContainer> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
var registration = Component.For(contractType).ImplementedBy(implementationType);
switch (lifetime)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/DryIoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IAbstractContainer<Container> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
var reuse = lifetime switch
{
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/IoCContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override IAbstractContainer<Container> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
var bind = _container.Bind(contractType);
switch (lifetime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override IAbstractContainer<Func<TContract>> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
_container.Bind(contractType, implementationType, lifetime, name);
return this;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/LightInject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override IAbstractContainer<ServiceContainer> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
switch (lifetime)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override IAbstractContainer<ServiceProvider> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
switch (lifetime)
{
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/Ninject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override IAbstractContainer<StandardKernel> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
var bind = _container.Bind(contractType).To(implementationType);
switch (lifetime)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/Containers/SimpleInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override IAbstractContainer<Container> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
switch (lifetime)
{
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/Pure.DI.Benchmarks/Containers/Unity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public override IAbstractContainer<UnityContainer> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default)
string? name = null)
{
ITypeLifetimeManager? lifetimeManager = default;
ITypeLifetimeManager? lifetimeManager = null;
switch (lifetime)
{
case AbstractLifetime.Transient:
Expand All @@ -28,7 +28,7 @@ public override IAbstractContainer<UnityContainer> Bind(
break;

default:
throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, default);
throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null);
}

((IUnityContainer)_container).RegisterType(contractType, implementationType, name, lifetimeManager);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Pure.DI.Benchmarks/IAbstractContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ IAbstractContainer<TActualContainer> Bind(
Type contractType,
Type implementationType,
AbstractLifetime lifetime = AbstractLifetime.Transient,
string? name = default);
string? name = null);
}
8 changes: 4 additions & 4 deletions build/Benchmarks/Thresholds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public readonly record struct Thresholds(
string Type = "",
string BaselineMethod = "",
string BenchmarkMethod = "",
double? WarningTimeRatio = default,
double? WarningBytesAllocatedPerOperationRatio = default,
double? ErrorTimeRatio = default,
double? ErrorBytesAllocatedPerOperationRatio = default);
double? WarningTimeRatio = null,
double? WarningBytesAllocatedPerOperationRatio = null,
double? ErrorTimeRatio = null,
double? ErrorBytesAllocatedPerOperationRatio = null);
12 changes: 9 additions & 3 deletions build/ReadmeTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static async Task AddContentAsync(string sourceFile, TextWriter readmeWr
foreach (var file in files)
{
var relativePath = Path.GetRelativePath(Environment.CurrentDirectory, file);
Part? part = default;
Part? part = null;
var vars = new Dictionary<string, string>
{
[VisibleKey] = "False",
Expand All @@ -151,7 +151,7 @@ private static async Task AddContentAsync(string sourceFile, TextWriter readmeWr

if (str.StartsWith("*/"))
{
part = default;
part = null;
continue;
}

Expand All @@ -171,7 +171,7 @@ private static async Task AddContentAsync(string sourceFile, TextWriter readmeWr
body.AddRange(localBody.Select(i => i.Length > offset ? i[offset..].TrimEnd() : i));
offset = int.MaxValue;
localBody.Clear();
part = default;
part = null;
continue;
}

Expand Down Expand Up @@ -212,6 +212,12 @@ private static async Task AddContentAsync(string sourceFile, TextWriter readmeWr
}
}

if (line.TrimStart().StartsWith("//# "))
{
localBody.Add(line.Replace("//# ", ""));
continue;
}

localBody.Add(line);
}
}
Expand Down
4 changes: 2 additions & 2 deletions build/Tools/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public string GetPath(PathType pathType) =>

private static string? TryFindFile(string? path, string searchPattern)
{
string? target = default;
while (path != default && target == default)
string? target = null;
while (path != null && target == null)
{
target = Directory.EnumerateFileSystemEntries(path, searchPattern).FirstOrDefault();
path = Path.GetDirectoryName(path);
Expand Down
2 changes: 1 addition & 1 deletion build/Tools/Sdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class Sdk

private static NuGetVersion[] GetVersions()
{
bool? getVersions = default;
bool? getVersions = null;
var versions = new List<NuGetVersion>();
new DotNetCustom("--info").Run(output =>
{
Expand Down
2 changes: 1 addition & 1 deletion readme/async-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/build-up-of-an-existing-generic-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/build-up-of-an-existing-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/check-for-a-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ partial class Composition
private static readonly HashSet<(Type type, object? tag)> Roots = [];

// Check that the root can be resolved by Resolve methods
internal static bool HasRoot(Type type, object? key = default) =>
internal static bool HasRoot(Type type, object? key = null) =>
Roots.Contains((type, key));

static void Setup() =>
Expand Down
2 changes: 1 addition & 1 deletion readme/class-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ partial class Composition
private readonly string _argServiceName;
private readonly string _argDependencyName;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition(int id, string serviceName, string dependencyName)
{
_argId = id;
Expand Down
2 changes: 1 addition & 1 deletion readme/complex-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ partial class Composition
private DependencyStruct<int> _singletonDependencyStruct51;
private bool _singletonDependencyStruct51Created;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/constructor-ordinal-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ partial class Composition

private readonly string _argServiceName;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition(string serviceName)
{
_argServiceName = serviceName ?? throw new ArgumentNullException(nameof(serviceName));
Expand Down
2 changes: 1 addition & 1 deletion readme/custom-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ partial class PersonComposition

private readonly int _argPersonId;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public PersonComposition(int personId)
{
_argPersonId = personId;
Expand Down
2 changes: 1 addition & 1 deletion readme/custom-universal-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ partial class PersonComposition

private readonly int _argPersonId;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public PersonComposition(int personId)
{
_argPersonId = personId;
Expand Down
2 changes: 1 addition & 1 deletion readme/exposed-generic-roots-with-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ partial class Composition

private Integration.CompositionWithGenericRootsAndArgsInOtherProject? _singletonCompositionWithGenericRootsAndArgsInOtherProject44;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/exposed-roots-via-arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ partial class Composition

private readonly Integration.CompositionInOtherProject _argBaseComposition;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition(Integration.CompositionInOtherProject baseComposition)
{
_argBaseComposition = baseComposition ?? throw new ArgumentNullException(nameof(baseComposition));
Expand Down
2 changes: 1 addition & 1 deletion readme/exposed-roots-via-root-arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(10)]
[OrdinalAttribute(128)]
public Composition()
{
_root = this;
Expand Down
Loading

0 comments on commit 18eccab

Please sign in to comment.