StructureMap Interceptor
-
05-09-2019 - |
Question
J'ai un tas de services qui mettent en œuvre différentes interfaces. par exemple, IAlbumService
, IMediaService
etc.
Je veux connecter des appels à chaque méthode sur ces interfaces. Comment puis-je faire cela en utilisant StructureMap?
Je sais que c'est à peu près la même chose que ce question il est juste que je ne suis pas en utilisant windsor.
La solution
Je pense que vous cherchez cette réponse .
static void Main()
{
ObjectFactory.Configure(x =>
{
x.For<Form>().Use<Form1>()
.InterceptWith(new ActivatorInterceptor<Form1>(y => Form1Interceptor(y), "Test"));
});
Application.Run(ObjectFactory.GetInstance<Form>());
}
public static void Form1Interceptor(Form f)
{
//Sets the title of the form window to "Testing"
f.Text = "Testing";
}
Je ne voudrais pas utiliser ObjectFactory dans une application réelle, mais au moins le concept est là.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow