예제 #1
0
        /// <summary>
        /// Creates and sets up a new instance Pyxis container
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="c"/> is <see langword="null" />.</exception>
        /// <exception cref="InvalidOperationException">Failed to setup container instance</exception>
        public static IContainer Setup(Action<IContainerConfiguration> c)
        {
            if (c == null)
            {
                throw new ArgumentNullException(nameof(c));
            }
            var conf = new FluentContainerConfigurator();

            try
            {
                c(conf);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Failed to setup container instance", exception);
            }

            var container = new ContainerImpl(conf);

            // register container instance
            conf.Register<IContainer>().Using(container);
            conf.Register<IServiceProvider>().Using(container);

            container.Build();
            return container;
        }
예제 #2
0
        public void ConfigurationShouldStoreRegistration()
        {
            var cfg = new FluentContainerConfigurator();
            var reg = cfg.Register<IStub>();

            cfg.Registrations.Should().Contain(x => x.Equals(reg));
        }
예제 #3
0
        public void RegistrationsOfSameTypeShouldNotEqualEachOther()
        {
            var cfg = new FluentContainerConfigurator();
            var reg1 = cfg.Register<IStub>().UsingConcreteType<Stub>();
            var reg2 = cfg.Register<IStub>().UsingConcreteType<StubWithDependency>();

            reg1.Should().NotBe(reg2);
        }
예제 #4
0
        public void ConfigurationShouldSupportMultipleRegistrationsOfTheSameContract()
        {
            var cfg = new FluentContainerConfigurator();
            var reg1 = cfg.Register<IStub>().UsingConcreteType<Stub>();
            var reg2 = cfg.Register<IStub>().UsingConcreteType<StubWithDependency>();

            cfg.Registrations.Should().HaveCount(2).And.Contain(x => x.Equals(reg1)).And.Contain(x => x.Equals(reg2));
        }
예제 #5
0
 public void RegistrationShouldNotFailOnRegistrationButAfterContainerBeginsInitialization()
 {
     var cfg = new FluentContainerConfigurator();
     var reg1 = cfg.Register<IStub>().UsingConcreteType<StubWithMultipleCtors>();
     var reg2 = cfg.Register<IStubDependency>().UsingConcreteType<StubDependency>();
 }