private Exception ThreadedScopeThreadRun(ManualResetEvent set, ManualResetEvent wait) { try { var container = new IoCContainer(); AmDisposable disp; using (var scope = new IoCScope()) { disp = container.GetInstance <AmDisposable>(); Assert.Equal(0, disp.DisposeCalled); Assert.Equal(1, scope.InstanceCount); set.Set(); wait.WaitOne(); Assert.Equal(1, scope.InstanceCount); var disp2 = container.GetInstance <AmDisposable>(); Assert.Same(disp, disp2); Assert.Equal(1, scope.InstanceCount); } Assert.Equal(1, disp.DisposeCalled); } catch (Exception exception) { return(exception); } return(null); }
private IocData(Type implType, Type serviceType, IoCScope scope) { if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } if (!serviceType.IsInterface) { throw new ArgumentException($"{nameof(serviceType)} should be interface"); } ImplType = implType; if (implType == null) { throw new ArgumentNullException(nameof(implType)); } if (!implType.IsClass || implType.IsAbstract) { throw new ArgumentException($"{nameof(implType)} should be non abstract class"); } ServiceType = serviceType; Scope = scope; }
public AutoRegister(IoCScope scope) { Scope = scope; }
public static void Register <TDef, TImpl>(IoCScope scope = IoCScope.InstancePerLifetimeScope) where TImpl : class, TDef { registerdTypes.Add(IocData.Create <TDef, TImpl>(scope)); }
public static IocData Create <TDef, TImpl>(IoCScope scope) where TImpl : class { return(new IocData(typeof(TImpl), typeof(TDef), scope)); }