/// <summary>Initializes a new instance of the <see cref="AspNetMvcDependencyResolver"/> class.</summary>
        /// <param name="compositionContext">The composition context.</param>
        public AspNetMvcDependencyResolver(CompositionContext compositionContext)
        {
            _compositionContext = compositionContext;

            var factory = new AspNetMvcControllerFactory(_compositionContext);
            _compositionContext.AddPart<IControllerFactory, AspNetMvcControllerFactory>(factory);
        }
        public void When_adding_by_type_then_object_should_automatically_be_instantiated()
        {
            var ctx = new CompositionContext();
            ctx.AddPart<ExportClass, ExportClass>();

            var obj = new ImportClass();
            ctx.SatisfyImports(obj);

            Assert.IsTrue(obj.Object != null);
        }
        public void When_adding_object_then_it_should_be_loadable()
        {
            var ctx = new CompositionContext();
            var part = new ExportClass();
            ctx.AddPart<ExportClass, ExportClass>(part);

            var obj = new ImportClass();
            ctx.SatisfyImports(obj);

            Assert.AreEqual(part, obj.Object);
        }
        public void When_instantiating_class_with_ctor_arguments_then_the_needed_objects_get_created()
        {
            var ctx = new CompositionContext();

            ctx.AddPart<ExportClass1, ExportClass1>();
            ctx.AddPart<ExportClassWithCtor, ExportClassWithCtor>();

            var part = ctx.GetPart<ExportClassWithCtor>();

            Assert.IsNotNull(part.Import);
            Assert.AreEqual(part.Import, ctx.GetPart<ExportClass1>());
        }
        public void When_adding_object_and_name_then_it_should_be_loadable()
        {
            var ctx = new CompositionContext();
            var part1 = new ExportClass();
            var part2 = new ExportClass();

            ctx.AddPart<ExportClass, ExportClass>(part1, "1");
            ctx.AddPart<ExportClass, ExportClass>(part2, "2");

            var obj = new ImportClass2();
            ctx.SatisfyImports(obj);

            Assert.AreEqual(part1, obj.Object1);
            Assert.AreEqual(part2, obj.Object2);
        }
        public void When_importing_many_objects_then_a_list_should_be_accessible()
        {
            var ctx = new CompositionContext();

            ctx.AddPart<ExportClass, ExportClass1>();
            ctx.AddPart<ExportClass, ExportClass2>();

            var obj = new ImportManyClass();
            ctx.SatisfyImports(obj);

            Assert.AreEqual(2, obj.Objects.Count());
        }
Exemple #7
0
 /// <summary>Registers a singleton service in the service locator where the service is lazily instantiated. </summary>
 /// <typeparam name="TInterface">The interface type of the service. </typeparam>
 /// <typeparam name="TImplementation">The implementation type of the service. </typeparam>
 public void RegisterSingleton <TInterface, TImplementation>()
 {
     _context.AddPart <TInterface, TImplementation>();
 }