Exemplo n.º 1
0
        public void Dispose()
        {
            var scopedResolver = ServiceResolver.CreateScope();
            var scoped         = scopedResolver.Resolve <IScoped>();

            scopedResolver.Dispose();
            Assert.True(scoped.IsDisposed);
        }
        public void Dispose()
        {
            var scopedResolver = ServiceResolver.CreateScope();
            var singleton      = ServiceResolver.Resolve <ISingleton>();

            scopedResolver.Dispose();
            Assert.False(singleton.IsDisposed);
            ServiceResolver.Dispose();
            Assert.True(singleton.IsDisposed);
        }
        public void Resolve_IServiceProvider()
        {
            var serviceResolver = ServiceResolver.Resolve <IServiceProvider>();

            Assert.Equal(ServiceResolver, serviceResolver);
            using (var scopedServiceResolver = ServiceResolver.CreateScope())
            {
                Assert.Equal(scopedServiceResolver, scopedServiceResolver.Resolve <IServiceProvider>());
            }
        }
        public void Equal()
        {
            var transient1 = ServiceResolver.Resolve <ITransient>();
            var transient2 = ServiceResolver.Resolve <ITransient>();

            using (var scopedResolver = ServiceResolver.CreateScope())
            {
                var transient3 = ServiceResolver.Resolve <ITransient>();
                Assert.NotEqual(transient1, transient2);
                Assert.NotEqual(transient2, transient3);
                Assert.NotEqual(transient1, transient3);
            }
        }
Exemplo n.º 5
0
        public void Get_Value()
        {
            var accessor1 = ServiceResolver.Resolve <ITransientServiceAccessor <ITransient> >();

            Assert.NotEqual(accessor1.Value, accessor1.Value);
            Assert.NotEqual(accessor1.Value, ServiceResolver.Resolve <ITransient>());
            using (var scope = ServiceResolver.CreateScope())
            {
                var accessor2 = scope.Resolve <ITransientServiceAccessor <ITransient> >();
                Assert.Equal(accessor1, accessor2);
                Assert.NotEqual(accessor1.Value, accessor2.Value);
            }
        }
        public void Resolve_Many_Lifetime()
        {
            var many  = ServiceResolver.ResolveMany <IService>().ToArray();
            var many1 = ServiceResolver.ResolveMany <IService>().ToArray();

            Assert.NotEqual(many[0], many1[0]);
            Assert.Equal(many[1], many1[1]);
            Assert.Equal(many[2], many1[2]);
            using (var scope = ServiceResolver.CreateScope())
            {
                var many2 = scope.Resolve <IEnumerable <IService> >().ToArray();
                Assert.NotEqual(many[0], many2[0]);
                Assert.Equal(many[1], many2[1]);
                Assert.NotEqual(many[2], many2[2]);
            }
        }
        public void Equal()
        {
            var singleton1 = ServiceResolver.Resolve <ISingleton>();

            using (var scopedResolver = ServiceResolver.CreateScope())
            {
                var singleton2 = scopedResolver.Resolve <ISingleton>();
                using (var scopedResolver1 = ServiceResolver.CreateScope())
                {
                    var singleton3 = scopedResolver1.Resolve <ISingleton>();
                    Assert.Equal(singleton1, singleton2);
                    Assert.Equal(singleton1, singleton3);
                    Assert.Equal(singleton2, singleton3);
                }
            }
        }
Exemplo n.º 8
0
        public void Equal()
        {
            var scoped1 = ServiceResolver.Resolve <IScoped>();

            using (var scopedResolver = ServiceResolver.CreateScope())
            {
                var scoped2 = scopedResolver.Resolve <IScoped>();
                var scoped3 = scopedResolver.Resolve <IScoped>();

                var scoped4 = ServiceResolver.Resolve <IScoped>();

                Assert.Equal(scoped1, scoped4);
                Assert.Equal(scoped2, scoped3);
                Assert.NotEqual(scoped1, scoped2);
                Assert.NotEqual(scoped1, scoped3);
                Assert.NotEqual(scoped2, scoped4);
                Assert.NotEqual(scoped3, scoped4);
            }
        }
Exemplo n.º 9
0
 public static IServiceProvider GetScopedServiceResolver() => ServiceResolver.CreateScope();