public void DisposalTest() { FauxInjectionScope injectionScope = new FauxInjectionScope(); CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(DisposableService), IsTransient = true, TrackDisposable = true, Attributes = new Attribute[0] }; FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new DisposableService(), null, injectionScope); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); FauxInjectionContext context = new FauxInjectionContext { DisposalScope = new DisposalScope() }; IDisposableService disposableService = (IDisposableService)activationDelegate(injectionScope, context); bool eventFired = false; disposableService.Disposing += (sender, args) => eventFired = true; context.DisposalScope.Dispose(); Assert.True(eventFired); }
/// <summary> /// Default constructor /// </summary> /// <param name="exportDelegateInfo"></param> /// <param name="activationDelegate"></param> /// <param name="exportStrategy"></param> /// <param name="owningScope"></param> public FuncCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, ExportActivationDelegate activationDelegate, IExportStrategy exportStrategy, IInjectionScope owningScope) : base(exportDelegateInfo,exportStrategy, owningScope) { exportActivationDelegate = activationDelegate; }
/// <summary> /// Default constructor /// </summary> /// <param name="exportType">export type</param> public SimpleExportStrategy(Type exportType) : base(exportType) { delegateInfo = new CompiledExportDelegateInfo { ActivationType = exportType, Attributes = ImmutableArray<Attribute>.Empty }; }
public BaseInjectionStrategy(Type targeType) { delegateInfo = new CompiledExportDelegateInfo { ActivationType = targeType, Attributes = targeType.GetTypeInfo().GetCustomAttributes() }; TargeType = targeType; }
/// <summary> /// Default Constructor /// </summary> /// <param name="exportType"></param> public CompiledExportStrategy(Type exportType) : base(exportType) { typeAttributes = new List<Attribute>(exportType.GetTypeInfo().GetCustomAttributes(true)).ToArray(); delegateInfo = new CompiledExportDelegateInfo { ActivationType = exportType, Attributes = typeAttributes }; }
public void EnrichWithTest() { CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(IBasicService), Attributes = new Attribute[0] }; info.EnrichWithDelegate((scope, context, injectObject) => new EnrichContainer(injectObject)); FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new BasicService(), null, new FauxInjectionScope()); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); EnrichContainer container = (EnrichContainer)activationDelegate(new FauxInjectionScope(), new FauxInjectionContext()); Assert.NotNull(container); Assert.NotNull(container.EnrichedObject); Assert.IsType(typeof(BasicService), container.EnrichedObject); }
/// <summary> /// Default Constructor /// </summary> /// <param name="exportDelegateInfo"></param> /// <param name="exportStrategy"></param> /// <param name="owningScope"></param> public InstanceCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, IExportStrategy exportStrategy, IInjectionScope owningScope) : base(exportDelegateInfo, exportStrategy, owningScope) { }
public SimpleCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, IExportStrategy exportStrategy) : base(exportDelegateInfo, exportStrategy,null) { }
public void ImportMethodTest() { FauxExportStrategy basicService = new FauxExportStrategy(() => new BasicService()) { ExportTypes = new[] { typeof(IBasicService) } }; FauxInjectionScope injectionScope = new FauxInjectionScope(); injectionScope.AddStrategy(basicService); CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(ImportMethodService), Attributes = new Attribute[0] }; info.ImportMethod(new ImportMethodInfo { MethodToImport = typeof(ImportMethodService).GetRuntimeMethod("ImportMethod", new[] { typeof(IBasicService) }) }); FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new ImportMethodService(), null, injectionScope); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); ImportMethodService propertyService = (ImportMethodService)activationDelegate(injectionScope, new InjectionContext(null, injectionScope)); Assert.NotNull(propertyService); }
public void SimpleExportTest() { CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(IBasicService), Attributes = new Attribute[0] }; FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new BasicService(), null, new FauxInjectionScope()); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); Assert.IsType(typeof(BasicService), activationDelegate(new FauxInjectionScope(), new FauxInjectionContext())); }
public void SimpleActivationMethodTest() { CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(ActivateService), IsTransient = true, TrackDisposable = true, Attributes = new Attribute[0] }; info.ActivateMethod(typeof(ActivateService).GetMethod("SimpleActivate")); FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new ActivateService(), null, new FauxInjectionScope()); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); ActivateService activateService = (ActivateService)activationDelegate(new FauxInjectionScope(), new FauxInjectionContext()); Assert.NotNull(activateService); Assert.True(activateService.SimpleActivateCalled); Assert.False(activateService.InjectionContextActivateCalled); }
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 MissingDisposalScopeTest() { FauxInjectionScope injectionScope = new FauxInjectionScope(); CompiledExportDelegateInfo info = new CompiledExportDelegateInfo { ActivationType = typeof(DisposableService), IsTransient = true, TrackDisposable = true, Attributes = new Attribute[0] }; FuncCompiledExportDelegate compiledExport = new FuncCompiledExportDelegate(info, (x, y) => new DisposableService(), null, injectionScope); ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate(); Assert.NotNull(activationDelegate); FauxInjectionContext context = new FauxInjectionContext(); try { IDisposableService disposableService = (IDisposableService)activationDelegate(injectionScope, context); throw new Exception("Should have thrown a DisposalScopeMissingException"); } catch (DisposalScopeMissingException) { } }
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 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); }