UseDependencyInjection
Gets or sets a value indicating whether the classes in scope receive their ICachingService from a dependency injection
container. The default value is false, which means that the cached methods use DefaultService.
Declaration
public bool UseDependencyInjection { get; set; }Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When this property is true, every class that has a method with CacheAttribute or
InvalidateCacheAttribute receives an ICachingService parameter in its public constructors, and the
classes that derive from it receive it too, also in other assemblies that PostSharp processes. The constructors assign the service just after the base constructor
call. A constructor that already has a parameter of type ICachingService uses it.
The original constructors are kept as non-public forwarders that pass null, so that a container sees only the
constructors that receive the service. An object created with new in the project goes through a forwarder and resolves the
service from RunTimeServiceLocator, where CachingServices registers
DefaultService unless the application registered another service first.
This changes the public constructors of the classes, which is a binary breaking change for their consumers.
Static methods have no object that receives the service: they use DefaultService, and the build reports a message with the severity given by StaticMethodFallbackSeverity.
This property is read at build time from the declaring type of the method, its base types and its assembly, in this order.