public void Should_create_the_proxy_once() { var tasks = Enumerable.Range(0, 5).Select(i => Task.Factory.StartNew(() => { ProxyGenerator.GetProxyType(typeof(ISomeDto)); })).ToArray(); Task.WaitAll(tasks); }
public IServiceProvider CreateServiceProvider(IServiceCollection services) { var description = services.FirstOrDefault(m => m.ServiceType == typeof(IFoo)); services.Remove(description); services.Add(new ServiceDescriptor(description.ImplementationType, description.ImplementationType, description.Lifetime)); services.Add(new ServiceDescriptor(typeof(IFoo), ProxyGenerator.GetProxyType(description.ImplementationType), description.Lifetime)); return(services.BuildServiceProvider()); }
public object CreateView(object implementation, Type implementationType, Type viewType) { if (!(implementationType.IsClass || implementationType.IsInterface)) { throw new ArgumentOutOfRangeException(nameof(implementationType)); } if (!viewType.IsInterface) { throw new ArgumentOutOfRangeException(nameof(viewType)); } var proxyType = ProxyGenerator.GetProxyType(implementationType, viewType); return(proxyType.CreateInstance(Interceptors, implementation)); }
object IMappingEngineRunner.CreateObject(ResolutionContext context) { var typeMap = context.TypeMap; var destinationType = context.DestinationType; if (typeMap != null) { if (typeMap.DestinationCtor != null) { return(typeMap.DestinationCtor(context)); } else if (typeMap.ConstructDestinationUsingServiceLocator && context.Options.ServiceCtor != null) { return(context.Options.ServiceCtor(destinationType)); } else if (typeMap.ConstructDestinationUsingServiceLocator) { return(_configurationProvider.ServiceCtor(destinationType)); } else if (typeMap.ConstructorMap != null) { return(typeMap.ConstructorMap.ResolveValue(context, this)); } } if (context.DestinationValue != null) { return(context.DestinationValue); } if (destinationType.IsInterface) { destinationType = ProxyGenerator.GetProxyType(destinationType); } return(ObjectCreator.CreateObject(destinationType)); }