private InstanceProducer TryGetProducerFromUnregisteredTypeResolutionCacheOrAdd( UnregisteredTypeEventArgs e) { Type serviceType = e.UnregisteredServiceType; var registration = e.Registration ?? new ExpressionRegistration(e.Expression, this); lock (this.resolveUnregisteredTypeRegistrations) { if (this.resolveUnregisteredTypeRegistrations.ContainsKey(serviceType)) { // This line will only get hit, in case a different thread came here first. return(this.resolveUnregisteredTypeRegistrations[serviceType]); } // By creating the InstanceProducer after checking the dictionary, we prevent the producer // from being created twice when multiple threads are running. Having the same duplicate // producer can cause a torn lifestyle warning in the container. var producer = new InstanceProducer(serviceType, registration); this.resolveUnregisteredTypeRegistrations[serviceType] = producer; return(producer); } }
private InstanceProducer TryGetInstanceProducerThroughResolveUnregisteredTypeEvent(Type serviceType) { if (this.resolveUnregisteredType == null) { return(null); } var e = new UnregisteredTypeEventArgs(serviceType); this.resolveUnregisteredType(this, e); return(e.Handled ? this.TryGetProducerFromUnregisteredTypeResolutionCacheOrAdd(e) : null); }
private InstanceProducer TryBuildInstanceProducerThroughUnregisteredTypeResolution(Type serviceType) { var e = new UnregisteredTypeEventArgs(serviceType); if (this.resolveUnregisteredType != null) { this.resolveUnregisteredType(this, e); } if (e.Handled) { var registration = e.Registration ?? new ExpressionRegistration(e.Expression, this); return(new InstanceProducer(serviceType, registration)); } else { return(null); } }