StructureMap intercettori
-
05-09-2019 - |
Domanda
Ho un sacco di servizi che implementano diverse interfacce. ad esempio, IAlbumService
, IMediaService
etc.
Voglio accedere chiamate a ogni metodo su queste interfacce. Come faccio a fare questo usando StructureMap?
Mi rendo conto che è più o meno lo stesso di questo domanda è solo che non sto usando Windsor.
Soluzione
Credo che siete alla ricerca di questa risposta .
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";
}
non vorrei usare ObjectFactory in un'applicazione reale, ma almeno il concetto è lì.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow