Created
April 17, 2014 13:48
-
-
Save mgroves/10984845 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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