public void TestCreationByNewFactorySingleton()
        {
            IDIContext context = ContextHelper.CreateContext();

            // Let's bind a test type using singleton binder
            context.s().Bind <IDependencyTest>(() => new DependencyTest());

            // Let's see that the dependencies are now injected - this class has injected context
            IDependencyTest test1 = context.Resolve <IDependencyTest>();
            IDependencyTest test2 = context.Resolve <IDependencyTest>();

            Assert.AreSame(test1, test2);
        }
        public void TestCreationByNew_IDICOntainerBranch()
        {
            IDIContext context = ContextHelper.CreateContext();

            // Let's bind a test type using a usual new
            context.s().Bind <IDependencyTest>(() => new DependencyTest());

            // Let's see that the dependencies are now injected - we have changed MinIOC. In original version this would fail
            IDependencyTest test = context.Resolve <IDependencyTest>();

            Assert.IsNotNull((test as IDIClosedContext).descriptor);
            Assert.IsNotNull((test as IDIClosedContext).descriptor.context);
            Assert.IsNotNull(test.contextAccess);
        }
        public void TestCreationByNewFactory()
        {
            IDIContext context = ContextHelper.CreateContext();

            // Then let's create a standard factory we will use
            SingletonBinder binder = new SingletonBinder(context);

            // Let's bind a test type using our factory
            binder.Bind <IDependencyTest>(() => new DependencyTest());

            // Let's see that the dependencies are now injected - this class has injected context
            IDependencyTest test = context.Resolve <IDependencyTest>();

            Assert.IsNotNull(test.contextAccess);
        }
        public void TestCreationByNewFactoryMultiple()
        {
            IDIContext context = ContextHelper.CreateContext();

            // Then let's create a standard factory we will use
            MultipleBinder binder = new MultipleBinder(context);

            // Let's bind a test type using our factory
            binder.Bind <IDependencyTest>(() => new DependencyTest());

            // Let's see that the dependencies are now injected - this class has injected context
            IDependencyTest test1 = context.Resolve <IDependencyTest>();
            IDependencyTest test2 = context.Resolve <IDependencyTest>();

            Assert.AreNotSame(test1, test2);
        }
Exemple #5
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger, IDependencyTest dependencyTest)
 {
     _logger         = logger;
     _dependencyTest = dependencyTest;
 }