Skip to main content
added 514 characters in body
Source Link
xenolightning
  • 4.2k
  • 1
  • 29
  • 35

I find the best place to go for any new versions is directly to the source.

If it's written well, then it will include test cases. Thankfully structuremap does include test cases.

You can explore the tests here

In the meantime I've written an example of an Activator Interceptor, and how to configure it.

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"; } 

EDIT:

How to use a "global" filter using PoliciesExpression

[STAThread] static void Main() { ObjectFactory.Configure(x => { x.Policies.Interceptors(new InterceptorPolicy<Form>(new FuncInterceptor<Form>(y => Intercept(y)))); }); Application.Run(ObjectFactory.GetInstance<Form>()); } private static Form Intercept(Form form) { //Do the interception here form.Text = "Testing"; return form; } 

I find the best place to go for any new versions is directly to the source.

If it's written well, then it will include test cases. Thankfully structuremap does include test cases.

You can explore the tests here

In the meantime I've written an example of an Activator Interceptor, and how to configure it.

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"; } 

I find the best place to go for any new versions is directly to the source.

If it's written well, then it will include test cases. Thankfully structuremap does include test cases.

You can explore the tests here

In the meantime I've written an example of an Activator Interceptor, and how to configure it.

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"; } 

EDIT:

How to use a "global" filter using PoliciesExpression

[STAThread] static void Main() { ObjectFactory.Configure(x => { x.Policies.Interceptors(new InterceptorPolicy<Form>(new FuncInterceptor<Form>(y => Intercept(y)))); }); Application.Run(ObjectFactory.GetInstance<Form>()); } private static Form Intercept(Form form) { //Do the interception here form.Text = "Testing"; return form; } 
Source Link
xenolightning
  • 4.2k
  • 1
  • 29
  • 35

I find the best place to go for any new versions is directly to the source.

If it's written well, then it will include test cases. Thankfully structuremap does include test cases.

You can explore the tests here

In the meantime I've written an example of an Activator Interceptor, and how to configure it.

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"; }