Beispiel #1
0
        public void GetRequireService()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <TestProxiedService>().As <IProxiedService>();
            var container       = builder.Build();
            var serviceProvider = new AutofacServiceProvider(container);

            Should.Throw <DependencyResolutionException>(() => serviceProvider.GetRequiredService(typeof(TestProxiedService)));
            Should.NotThrow(() => serviceProvider.GetRequiredService(typeof(IProxiedService))).ShouldNotBeNull();
        }
Beispiel #2
0
        public void Dispose()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <TestProxiedService>().As <IProxiedService>();
            var container       = builder.Build();
            var serviceProvider = new AutofacServiceProvider(container);

            Should.NotThrow(() => serviceProvider.GetRequiredService(typeof(IProxiedService))).ShouldNotBeNull();
            serviceProvider.Dispose();
            Should.Throw <ObjectDisposedException>(() => serviceProvider.GetRequiredService(typeof(IProxiedService)));
        }