Skip to content

Instantly share code, notes, and snippets.

@hikalkan
Created October 15, 2014 05:42
Show Gist options
  • Save hikalkan/1e5d0f0142484da994e0 to your computer and use it in GitHub Desktop.
Save hikalkan/1e5d0f0142484da994e0 to your computer and use it in GitHub Desktop.
Castle Windsor interceptor for async methods
class Program
{
static void Main(string[] args)
{
using (var container = new WindsorContainer())
{
container.Register(
Component.For<MyInterceptor>().LifestyleTransient(),
Component.For<MyTester>().Interceptors<MyInterceptor>().LifestyleTransient()
);
var tester = container.Resolve<MyTester>();
var r = tester.Test();
Console.WriteLine("2");
r.Wait();
Console.WriteLine("4");
}
Console.ReadLine();
}
}
public class MyTester
{
public virtual async Task Test()
{
using (var str = new StreamWriter(@"c:\_test_delete_later.txt"))
{
Console.WriteLine("1");
for (int i = 0; i < 1000000; i++)
{
await str.WriteLineAsync("Test " + i);
}
Console.WriteLine("3");
}
}
}
public class MyInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
invocation.Proceed();
}
}
@webzfactory
Copy link

I did exactly the same thing and got the same errors, so I used task.wait()... and I am now disappointed of not being able to make it work as it should... but we are close to the solution I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment