Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created April 17, 2014 13:48
Show Gist options
  • Select an option

  • Save mgroves/10984845 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/10984845 to your computer and use it in GitHub Desktop.
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
// just a plain C# decorator
x.For<IReportService>().Use<ReportService>()
.EnrichWith(i => new ReportCacheDecorator(i));
// Castle DynamicProxy generated decorator
var proxyGenerator = new ProxyGenerator();
x.For<IReportService>().Use<ReportService>()
.EnrichWith(i => proxyGenerator.CreateInterfaceProxyWithTargetInterface<IReportService>(i, new CacheInterceptor()));
});
return ObjectFactory.Container;
}
}
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
// just a plain C# decorator
x.For<IReportService>().Use<ReportService>()
.DecorateWith(i => new ReportCacheDecorator(i));
// Castle DynamicProxy generated decorator
// notice I was able to drop the explicit type parameter on CreateInterfaceProxyWithTargetInterface
var proxyGenerator = new ProxyGenerator();
x.For<IReportService>().Use<ReportService>()
.DecorateWith(i => proxyGenerator.CreateInterfaceProxyWithTargetInterface(i, new CacheInterceptor()));
});
return ObjectFactory.Container;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment