Skip to content

Proxy Service

Kengwang edited this page Jan 29, 2024 · 1 revision

As the Law of Demeter, the other service will not know if it is using directly a service or its proxy, you can set proxy just on Depository.

depository.AddSingleton<IGuidGenerator, EmptyGuidGenerator>();
depository.SetDependencyDecoration<IGuidGenerator, GuidDecorationService>();

and then any other place to resolve IGuidGenerator will only get GuidDecorationService, but in GuidDecorationService, you can resolve actual services.

This also applies to IEnumerable

Clone this wiki locally