Registers an ResolveInterceptor delegate that allows intercepting calls to
GetInstance and
GetInstance.
Namespace: SimpleInjector
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax
public void RegisterResolveInterceptor( ResolveInterceptor interceptor, Predicate<InitializationContext> predicate )
Parameters
- interceptor
- Type: SimpleInjectorResolveInterceptor
The ResolveInterceptor delegate to register. - predicate
- Type: SystemPredicateInitializationContext
The predicate that will be used to check whether the given delegate must be applied to a registration or not. The given predicate will be called once for each registration in the container.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | Thrown when either the interceptor or predicate are null references. |
InvalidOperationException | Thrown when this container instance is locked and can not be altered. |
Remarks
Examples
C#
var container = new Container(); container.Options.RegisterResolveInterceptor((context, producer) => { object instance = producer.Invoke(); Console.WriteLine(instance.GetType().Name + " resolved for " + context.Producer.ServiceType.Name); return instance; }, context => context.Producer.ServiceType.Name.EndsWith("Controller")); container.Register<IHomeViewModel, HomeViewModel>(); container.Register<IUserRepository, SqlUserRepository>(); // This line will write "HomeViewModel resolved for IHomeViewModel" to the console. container.GetInstance<IHomeViewModel>();
See Also