Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed May 23, 2024
1 parent cfb64d1 commit 121dd4c
Show file tree
Hide file tree
Showing 39 changed files with 397 additions and 413 deletions.
2 changes: 1 addition & 1 deletion readme/Avalonia.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The definition of the composition is in [Composition.cs](/samples/AvaloniaApp/Co
```csharp
internal partial class Composition
{
void Setup() => DI.Setup(nameof(Composition))
void Setup() => DI.Setup()
// Provides the composition root for main window
.Root<MainWindow>("MainWindow")
// Provides the composition root for Clock view model
Expand Down
2 changes: 1 addition & 1 deletion readme/AvaloniaPageTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The definition of the composition is in [Composition.cs](/samples/AvaloniaApp/Co
```csharp
internal partial class Composition
{
void Setup() => DI.Setup(nameof(Composition))
void Setup() => DI.Setup()
// Provides the composition root for main window
.Root<MainWindow>("MainWindow")
// Provides the composition root for Clock view model
Expand Down
63 changes: 31 additions & 32 deletions readme/BlazorServerApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@ Composition setup file is [Composition.cs](/samples/BlazorServerApp/Composition.
```c#
internal partial class Composition: ServiceProviderFactory<Composition>
{
void Setup() =>
DI.Setup(nameof(Composition))
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

// Infrastructure
.Bind().To<Dispatcher>();
void Setup() => DI.Setup()
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

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

Expand Down
63 changes: 31 additions & 32 deletions readme/BlazorServerAppPageTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@ Composition setup file is [Composition.cs](/samples/BlazorServerApp/Composition.
```c#
internal partial class Composition: ServiceProviderFactory<Composition>
{
void Setup() =>
DI.Setup(nameof(Composition))
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

// Infrastructure
.Bind().To<Dispatcher>();
void Setup() => DI.Setup()
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

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

Expand Down
57 changes: 28 additions & 29 deletions readme/BlazorWebAssemblyApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@ Composition setup file is [Composition.cs](/samples/BlazorWebAssemblyApp/Composi
```c#
internal partial class Composition: ServiceProviderFactory<Composition>
{
void Setup() =>
DI.Setup(nameof(Composition))
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

// Infrastructure
.Bind().To<Dispatcher>();
void Setup() => DI.Setup()
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

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

Expand Down
57 changes: 28 additions & 29 deletions readme/BlazorWebAssemblyAppPageTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@ Composition setup file is [Composition.cs](/samples/BlazorWebAssemblyApp/Composi
```c#
internal partial class Composition: ServiceProviderFactory<Composition>
{
void Setup() =>
DI.Setup(nameof(Composition))
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

// Infrastructure
.Bind().To<Dispatcher>();
void Setup() => DI.Setup()
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

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

// Services
.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().As(Singleton).To<CounterService>()
// Provides the composition root for Counter service
.Root<ICounterService>()

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

Expand Down
31 changes: 15 additions & 16 deletions readme/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,21 @@ internal partial class Composition
// In fact, this code is never run, and the method can have any name or be a constructor, for example,
// and can be in any part of the compiled code because this is just a hint to set up an object graph.
// Here the setup is part of the generated class, just as an example.
void Setup() =>
DI.Setup(nameof(Composition))
// Models a random subatomic event that may or may not occur
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
// Represents schrodinger's cat
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any content
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");
void Setup() => DI.Setup()
// Models a random subatomic event that may or may not occur
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
// Represents schrodinger's cat
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any content
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");
}

// Time to open boxes!
Expand Down
31 changes: 15 additions & 16 deletions readme/ConsolePageTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,21 @@ internal partial class Composition
// In fact, this code is never run, and the method can have any name or be a constructor, for example,
// and can be in any part of the compiled code because this is just a hint to set up an object graph.
// Here the setup is part of the generated class, just as an example.
void Setup() =>
DI.Setup(nameof(Composition))
// Models a random subatomic event that may or may not occur
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
// Represents schrodinger's cat
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any content
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");
void Setup() => DI.Setup()
// Models a random subatomic event that may or may not occur
.Bind().As(Singleton).To<Random>()
// Represents a quantum superposition of 2 states: Alive or Dead
.Bind().To(ctx =>
{
ctx.Inject<Random>(out var random);
return (State)random.Next(2);
})
// Represents schrodinger's cat
.Bind().To<ShroedingersCat>()
// Represents a cardboard box with any content
.Bind().To<CardboardBox<TT>>()
// Composition Root
.Root<Program>("Root");
}

// Time to open boxes!
Expand Down
23 changes: 11 additions & 12 deletions readme/GrpcService.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ Composition setup file is [Composition.cs](/samples/GrpcService/Composition.cs):
```c#
internal partial class Composition: ServiceProviderFactory<Composition>
{
void Setup() =>
DI.Setup(nameof(Composition))
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

// Provides the composition root for Greeter service
.Root<GreeterService>();
void Setup() => DI.Setup()
.DependsOn(Base)
// Specifies not to attempt to resolve types whose fully qualified name
// begins with Microsoft.Extensions., Microsoft.AspNetCore.
// since ServiceProvider will be used to retrieve them.
.Hint(
Hint.OnCannotResolveContractTypeNameRegularExpression,
@"^Microsoft\.(Extensions|AspNetCore)\..+$")

// Provides the composition root for Greeter service
.Root<GreeterService>();
}
```

Expand Down
Loading

0 comments on commit 121dd4c

Please sign in to comment.