Property interception
Intercept setters
Use the following code:
var serviceLocator = ServiceLocator.Default; serviceLocator.ConfigureInterceptionForType<ITestService, TestService>() .InterceptSetter(service => service.Name) .OnBefore(() => Console.WriteLine("Setting Property Intercepted")); var testService = serviceLocator.ResolveType<ITestService>(); testService.Name = "testValue"; var name = testService.Name;
The output will look like this:
Setting Property intercepted
Intercept getters
Use the following code:
var serviceLocator = ServiceLocator.Default; serviceLocator.ConfigureInterceptionForType<ITestService, TestService>() .InterceptGetter(service => service.Name) .OnBefore(() => Console.WriteLine("Getting Property Intercepted")); var testService = serviceLocator.ResolveType<ITestService>(); testService.Name = "testValue"; var name = testService.Name;
The output will look like this:
Getting Property intercepted