main
1using System;
2using Castle.Core.Interceptor;
3using Castle.DynamicProxy;
4using Gorilla.Commons.Infrastructure.Container;
5using gorilla.commons.infrastructure.thirdparty.castle.dynamicproxy;
6using gorilla.commons.utility;
7
8namespace gorilla.commons.infrastructure.thirdparty.Castle.DynamicProxy
9{
10 public static class Lazy
11 {
12 public static T load<T>() where T : class
13 {
14 return create_proxy_for<T>(create_interceptor_for<T>());
15 }
16
17 static IInterceptor create_interceptor_for<T>() where T : class
18 {
19 Func<T> get_the_implementation = Resolve.the<T>;
20 return new LazyLoadedInterceptor<T>(get_the_implementation.memorize());
21 }
22
23 static T create_proxy_for<T>(IInterceptor interceptor)
24 {
25 return new ProxyGenerator().CreateInterfaceProxyWithoutTarget<T>(interceptor);
26 }
27 }
28}