Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 7, 2024
1 parent 802840e commit 22a1a28
Show file tree
Hide file tree
Showing 83 changed files with 2,094 additions and 2,074 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ partial class Composition
private static void Setup() =>
DI.Setup(nameof(Composition))
// Models a random subatomic event that may or may not occur
.Bind<Random>().As(Singleton).To<Random>()
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind<State>().To(ctx =>
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
.Bind<ICat>().To<ShroedingersCat>()
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any contents
.Bind<IBox<TT>>().To<CardboardBox<TT>>()
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");
}
Expand Down Expand Up @@ -199,6 +199,7 @@ dotnet run
### Basics
- [Auto-bindings](readme/auto-bindings.md)
- [Injections of abstractions](readme/injections-of-abstractions.md)
- [Abstractions binding](readme/abstractions-binding.md)
- [Composition roots](readme/composition-roots.md)
- [Resolve methods](readme/resolve-methods.md)
- [Factory](readme/factory.md)
Expand All @@ -207,6 +208,8 @@ dotnet run
- [Arguments](readme/arguments.md)
- [Root arguments](readme/root-arguments.md)
- [Composition root kinds](readme/composition-root-kinds.md)
- [Tag Type](readme/tag-type.md)
- [Tag Unique](readme/tag-unique.md)
- [Tags](readme/tags.md)
- [Multi-contract bindings](readme/multi-contract-bindings.md)
- [Field injection](readme/field-injection.md)
Expand Down
42 changes: 21 additions & 21 deletions readme/ArrayDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ classDiagram
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
partial class Array
{
private readonly Array _rootM03D01di;
private readonly Array _rootM03D07di;

/// <summary>
/// This constructor creates a new instance of <see cref="Array"/>.
/// </summary>
public Array()
{
_rootM03D01di = this;
_rootM03D07di = this;
}

/// <summary>
Expand All @@ -132,7 +132,7 @@ partial class Array
/// <param name="baseComposition">Base composition.</param>
internal Array(Array baseComposition)
{
_rootM03D01di = baseComposition._rootM03D01di;
_rootM03D07di = baseComposition._rootM03D07di;
}

#region Composition Roots
Expand All @@ -156,7 +156,7 @@ partial class Array
#endif
public T Resolve<T>()
{
return ResolverM03D01di<T>.Value.Resolve(this);
return ResolverM03D07di<T>.Value.Resolve(this);
}

/// <summary>
Expand All @@ -170,7 +170,7 @@ partial class Array
#endif
public T Resolve<T>(object? tag)
{
return ResolverM03D01di<T>.Value.ResolveByTag(this, tag);
return ResolverM03D07di<T>.Value.ResolveByTag(this, tag);
}

/// <summary>
Expand All @@ -183,10 +183,10 @@ partial class Array
#endif
public object Resolve(global::System.Type type)
{
var index = (int)(_bucketSizeM03D01di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM03D01di;
var index = (int)(_bucketSizeM03D07di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM03D07di;
do {
ref var pair = ref _bucketsM03D01di[index];
ref var pair = ref _bucketsM03D07di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
Expand All @@ -207,10 +207,10 @@ partial class Array
#endif
public object Resolve(global::System.Type type, object? tag)
{
var index = (int)(_bucketSizeM03D01di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM03D01di;
var index = (int)(_bucketSizeM03D07di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM03D07di;
do {
ref var pair = ref _bucketsM03D01di[index];
ref var pair = ref _bucketsM03D07di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
Expand Down Expand Up @@ -303,26 +303,26 @@ partial class Array
" Array ..> CompositionRoot : CompositionRoot PureDIByCR";
}

private readonly static int _bucketSizeM03D01di;
private readonly static global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>[] _bucketsM03D01di;
private readonly static int _bucketSizeM03D07di;
private readonly static global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>[] _bucketsM03D07di;

static Array()
{
var valResolverM03D01di_0000 = new ResolverM03D01di_0000();
ResolverM03D01di<Pure.DI.Benchmarks.Model.CompositionRoot>.Value = valResolverM03D01di_0000;
_bucketsM03D01di = global::Pure.DI.Buckets<global::System.Type, global::Pure.DI.IResolver<Array, object>>.Create(
var valResolverM03D07di_0000 = new ResolverM03D07di_0000();
ResolverM03D07di<Pure.DI.Benchmarks.Model.CompositionRoot>.Value = valResolverM03D07di_0000;
_bucketsM03D07di = global::Pure.DI.Buckets<global::System.Type, global::Pure.DI.IResolver<Array, object>>.Create(
1,
out _bucketSizeM03D01di,
out _bucketSizeM03D07di,
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>[1]
{
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM03D01di_0000)
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM03D07di_0000)
});
}

#region Resolvers
private sealed class ResolverM03D01di<T>: global::Pure.DI.IResolver<Array, T>
private sealed class ResolverM03D07di<T>: global::Pure.DI.IResolver<Array, T>
{
public static global::Pure.DI.IResolver<Array, T> Value = new ResolverM03D01di<T>();
public static global::Pure.DI.IResolver<Array, T> Value = new ResolverM03D07di<T>();

public T Resolve(Array composite)
{
Expand All @@ -335,7 +335,7 @@ partial class Array
}
}

private sealed class ResolverM03D01di_0000: global::Pure.DI.IResolver<Array, Pure.DI.Benchmarks.Model.CompositionRoot>
private sealed class ResolverM03D07di_0000: global::Pure.DI.IResolver<Array, Pure.DI.Benchmarks.Model.CompositionRoot>
{
public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Array composition)
{
Expand Down
15 changes: 8 additions & 7 deletions readme/Avalonia.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ The definition of the composition is in [Composition.cs](/samples/AvaloniaApp/Co
internal partial class Composition
{
private static void Setup() => DI.Setup(nameof(Composition))
// Root
// Provides the composition root for main window
.Root<MainWindow>("MainWindow")
// Provides the composition root for Clock view model
.Root<IClockViewModel>("ClockViewModel")

// View Models
.Bind<IClockViewModel>().As(Singleton).To<ClockViewModel>()
.Bind().As(Singleton).To<ClockViewModel>()

// Models
.Bind<ILog<TT>>().To<Log<TT>>()
.Bind<TimeSpan>().To(_ => TimeSpan.FromSeconds(1))
.Bind<ITimer>().As(Singleton).To<Clock.Models.Timer>()
.Bind<IClock>().As(PerBlock).To<SystemClock>()
.Bind().To<Log<TT>>()
.Bind().To(_ => TimeSpan.FromSeconds(1))
.Bind().As(Singleton).To<Clock.Models.Timer>()
.Bind().As(PerBlock).To<SystemClock>()

// Infrastructure
.Bind<IDispatcher>().To<Dispatcher>();
.Bind().To<Dispatcher>();
}
```

Expand Down
30 changes: 14 additions & 16 deletions readme/BlazorServerApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,30 @@ internal partial class Composition: ServiceProviderFactory<Composition>
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
"^Microsoft\\.(Extensions|AspNetCore)\\..+$")
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

// View Models
.Bind<IClockViewModel>()
.To<ClockViewModel>()
.Bind().To<ClockViewModel>()
// Provides the composition root for Clock view model
.Root<IClockViewModel>("ClockViewModel")
.Bind<IErrorViewModel>()
.To<ErrorViewModel>()
.Bind().To<ErrorViewModel>()
// Provides the composition root for Error view model
.Root<IErrorViewModel>()

// Services
.Bind<ILog<TT>>().To<Log<TT>>()
.Bind<TimeSpan>().To(_ => TimeSpan.FromSeconds(1))
.Bind<ITimer>().As(Singleton).To<Timer>()
.Bind<IClock>().As(PerBlock).To<SystemClock>()
.Bind<IWeatherForecastService>()
.As(Singleton)
.To<WeatherForecastService>()
.Bind().To<Log<TT>>()
.Bind().To(_ => TimeSpan.FromSeconds(1))
.Bind().As(Singleton).To<Timer>()
.Bind().As(PerBlock).To<SystemClock>()
.Bind().As(Singleton).To<WeatherForecastService>()
// Provides the composition root for Weather Forecast service
.Root<IWeatherForecastService>()
.Bind<ICounterService>()
.As(Singleton)
.To<CounterService>()
.Bind().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

// Infrastructure
.Bind<IDispatcher>().To<Dispatcher>();
.Bind().To<Dispatcher>();
}
```

Expand Down
27 changes: 12 additions & 15 deletions readme/BlazorWebAssemblyApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ internal partial class Composition: ServiceProviderFactory<Composition>
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
"^Microsoft\\.(Extensions|AspNetCore)\\..+$")
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

// View Models
.Bind<IClockViewModel>()
.As(Singleton)
.To<ClockViewModel>()
.Bind().As(Singleton).To<ClockViewModel>()
// Provides the composition root for Clock view model
.Root<IClockViewModel>("ClockViewModel")

// Services
.Bind<ILog<TT>>().To<Log<TT>>()
.Bind<TimeSpan>().To(_ => TimeSpan.FromSeconds(1))
.Bind<ITimer>().As(Singleton).To<Timer>()
.Bind<IClock>().As(PerBlock).To<SystemClock>()
.Bind<IWeatherForecastService>()
.As(Singleton)
.To<WeatherForecastService>()
.Bind().To<Log<TT>>()
.Bind().To(_ => TimeSpan.FromSeconds(1))
.Bind().As(Singleton).To<Timer>()
.Bind().As(PerBlock).To<SystemClock>()
.Bind().As(Singleton).To<WeatherForecastService>()
// Provides the composition root for Weather Forecast service
.Root<IWeatherForecastService>()
.Bind<ICounterService>()
.As(Singleton)
.To<CounterService>()
.Bind().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

// Infrastructure
.Bind<IDispatcher>().To<Dispatcher>();
.Bind().To<Dispatcher>();
}
```

Expand Down
8 changes: 4 additions & 4 deletions readme/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ internal partial class Composition
private static void Setup() =>
DI.Setup(nameof(Composition))
// Models a random subatomic event that may or may not occur
.Bind<Random>().As(Singleton).To<Random>()
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind<State>().To(ctx =>
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
// Represents schrodinger's cat
.Bind<ICat>().To<ShroedingersCat>()
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any content
.Bind<IBox<TT>>().To<CardboardBox<TT>>()
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");
}
Expand Down
8 changes: 4 additions & 4 deletions readme/ConsoleTopLevelStatements.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ new Composition().Root.Run();
// and can be in any part of the compiled code because this is just a hint to set up an object graph.
DI.Setup("Composition")
// Models a random subatomic event that may or may not occur
.Bind<Random>().As(Singleton).To<Random>()
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind<State>().To(ctx =>
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
// Represents schrodinger's cat
.Bind<ICat>().To<ShroedingersCat>()
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any content
.Bind<IBox<TT>>().To<CardboardBox<TT>>()
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");

Expand Down
Loading

0 comments on commit 22a1a28

Please sign in to comment.