public void AutofacContainerBuilderTests_TypesRegistrableAsSelf_NewAPI()
        {
            //Arrange
            var autofacContainerBuilder = new AutofacContainerBuilder();

            //Act
            autofacContainerBuilder.For(typeof(Foo));
            var dependencyResolver = autofacContainerBuilder.Build();

            //Assert
            Assert.IsNotNull(dependencyResolver.Resolve <Foo>());
        }
        public void AutofacContainerBuilderTests_TypesRegistrableAsInterfaces()
        {
            //Arrange
            var autofacContainerBuilder = new AutofacContainerBuilder();

            //Act
            autofacContainerBuilder.For <Foo>()
            .KnownAs <IFoo>();
            var dependencyResolver = autofacContainerBuilder.Build();

            //Assert
            Assert.IsNotNull(dependencyResolver.Resolve <IFoo>());
        }
        public void DependencyRegistrarExtensions_KnwonAsSelf_RegistersTypeAsItself()
        {
            //Arrange
            var builder = new AutofacContainerBuilder();

            //Act
            builder.For(typeof(Foo))
            .KnownAsSelf();
            var resolver = builder.Build();

            //Assert
            Assert.IsNotNull(resolver.Resolve <Foo>());
        }
Пример #4
0
        public void AutofacContainerBuilder_WithTests_ProvidedMetaData_MappedToInstance()
        {
            //Arrange
            var builder = new AutofacContainerBuilder();

            //Act
            builder.For <Foo>()
            .WithMetadata <Metadata, string>(am => am.Value, "test");

            var resolver = builder.Build();

            //Assert
            var lazyFoo = resolver.Resolve <Lazy <Foo, Metadata> >();

            Assert.IsNotNull(lazyFoo);
            Assert.AreEqual("test", lazyFoo.Metadata.Value);
        }
Пример #5
0
        public void RebelAreaRegistrationReceivesMetadataFromIoC()
        {
            var codeBase     = Assembly.GetExecutingAssembly().CodeBase;
            var uri          = new Uri(codeBase);
            var path         = uri.LocalPath;
            var binFolder    = Path.GetDirectoryName(path);
            var settingsFile = new FileInfo(Path.Combine(binFolder, "web.config"));

            var autofacBuilder = new AutofacContainerBuilder();

            autofacBuilder.ForFactory(
                context => new RebelSettings(settingsFile))
            .KnownAsSelf();

            autofacBuilder.For <RebelAreaRegistration>()
            .KnownAsSelf()
            .WithResolvedParam(context => context.Resolve <IRouteHandler>("TreeRouteHandler"));

            //why is this here?

            var typeFinder         = new TypeFinder();
            var componentRegistrar = new RebelComponentRegistrar();

            componentRegistrar.RegisterEditorControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterMenuItems(autofacBuilder, typeFinder);
            //componentRegistrar.RegisterPackageActions(autofacBuilder, typeFinder);
            componentRegistrar.RegisterPropertyEditors(autofacBuilder, typeFinder);
            componentRegistrar.RegisterSurfaceControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterTreeControllers(autofacBuilder, typeFinder);

            //build the container
            var container = autofacBuilder.Build();

            var result = container.Resolve <RebelAreaRegistration>();

            Assert.IsNotNull(result);
        }
        public void UmbracoAreaRegistrationReceivesMetadataFromIoC()
        {
            var codeBase = Assembly.GetExecutingAssembly().CodeBase;
            var uri = new Uri(codeBase);
            var path = uri.LocalPath;
            var binFolder = Path.GetDirectoryName(path);
            var settingsFile = new FileInfo(Path.Combine(binFolder, "web.config"));

            var autofacBuilder = new AutofacContainerBuilder();

            autofacBuilder.ForFactory(
                context => new UmbracoSettings(settingsFile))
                .KnownAsSelf();

            autofacBuilder.For<UmbracoAreaRegistration>()
                .KnownAsSelf()
                .WithResolvedParam(context => context.Resolve<IRouteHandler>("TreeRouteHandler"));

            //why is this here? 

            var typeFinder = new TypeFinder();
            var componentRegistrar = new UmbracoComponentRegistrar();
            componentRegistrar.RegisterEditorControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterMenuItems(autofacBuilder, typeFinder);
            //componentRegistrar.RegisterPackageActions(autofacBuilder, typeFinder);
            componentRegistrar.RegisterPropertyEditors(autofacBuilder, typeFinder);
            componentRegistrar.RegisterSurfaceControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterTreeControllers(autofacBuilder, typeFinder);

            //build the container
            var container = autofacBuilder.Build();

            var result = container.Resolve<UmbracoAreaRegistration>();

            Assert.IsNotNull(result);
        }