示例#1
0
        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);
        }
示例#2
0
        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;
        }
示例#3
0
 public AutoRegister(IoCScope scope)
 {
     Scope = scope;
 }
示例#4
0
 public static void Register <TDef, TImpl>(IoCScope scope = IoCScope.InstancePerLifetimeScope)
     where TImpl : class, TDef
 {
     registerdTypes.Add(IocData.Create <TDef, TImpl>(scope));
 }
示例#5
0
 public static IocData Create <TDef, TImpl>(IoCScope scope) where TImpl : class
 {
     return(new IocData(typeof(TImpl), typeof(TDef), scope));
 }