public void ImportPropertyRootTransientTest() { FauxExportStrategy basicService = new FauxExportStrategy(() => new BasicService()) { ExportTypes = new[] { typeof(IBasicService) } }; FauxInjectionScope injectionScope = new FauxInjectionScope(); injectionScope.AddStrategy(basicService); CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(ImportPropertyService), IsTransient = true, Attributes = new Attribute[0] }; info.ImportProperty(new ImportPropertyInfo { Property = typeof(ImportPropertyService).GetProperty("BasicService") }); FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new ImportPropertyService(), null, injectionScope); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); IImportPropertyService propertyService = (IImportPropertyService)activationDelegate(injectionScope, new InjectionContext(null, injectionScope)); Assert.NotNull(propertyService); Assert.NotNull(propertyService.BasicService); }
public void PropertyImportProviderTest() { FauxInjectionScope injectionScope = new FauxInjectionScope(); CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(ImportPropertyService), Attributes = new Attribute[0] }; info.ImportProperty(new ImportPropertyInfo { Property = typeof(ImportPropertyService).GetProperty("BasicService"), ValueProvider = new FuncValueProvider<IBasicService>(() => new BasicService()) }); FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new ImportPropertyService(), null, injectionScope); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); IImportPropertyService propertyService = (IImportPropertyService)activationDelegate(injectionScope, new InjectionContext(null, injectionScope)); Assert.NotNull(propertyService); Assert.NotNull(propertyService.BasicService); }
public void ImportPropertyNonRootTransienTest() { FauxExportStrategy basicService = new FauxExportStrategy(() => new BasicService()) { ExportTypes = new[] { typeof(IBasicService) } }; InjectionKernelManager manager = new InjectionKernelManager(null, DependencyInjectionContainer.CompareExportStrategies, new BlackList()); InjectionKernel injectionScope = new InjectionKernel(manager, null, null, "Root", DependencyInjectionContainer.CompareExportStrategies); injectionScope.AddStrategy(basicService); CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(ImportPropertyService), IsTransient = true, Attributes = new Attribute[0] }; info.ImportProperty(new ImportPropertyInfo { Property = typeof(ImportPropertyService).GetProperty("BasicService") }); FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new ImportPropertyService(), null, injectionScope); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); IInjectionScope requestingScope = injectionScope.CreateChildScope(); IImportPropertyService propertyService = (IImportPropertyService)activationDelegate(injectionScope, new InjectionContext(null, requestingScope)); Assert.NotNull(propertyService); Assert.NotNull(propertyService.BasicService); }