-
Notifications
You must be signed in to change notification settings - Fork 22
/
Composition.cs
48 lines (41 loc) · 1.58 KB
/
Composition.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ReSharper disable UnusedMember.Local
// ReSharper disable ArrangeTypeMemberModifiers
namespace BlazorServerApp;
using Clock.Models;
using Clock.ViewModels;
using Models;
using Pure.DI;
using Pure.DI.MS;
using WeatherForecast;
using static Pure.DI.Lifetime;
internal partial class Composition : ServiceProviderFactory<Composition>
{
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>(nameof(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>();
}