public static void ReplaceActiveDiManagerInConfigurationFile(XmlDocument xmlDocument, DiImplementationType diImplementationType) { string activeDiManagerName = null; switch (diImplementationType) { case DiImplementationType.Autofac: case DiImplementationType.Ninject: activeDiManagerName = diImplementationType.ToString(); break; default: throw new Exception($"The value is not handled: {diImplementationType}."); } xmlDocument.SelectElement("/iocConfiguration/diManagers", x => true) .SetAttributeValue(ConfigurationFileAttributeNames.ActiveDiManagerName, activeDiManagerName); }
private void ConfigurationFileXmlDocumentLoadedEventHandler([CanBeNull] object sender, [NotNull] ConfigurationFileXmlDocumentLoadedEventArgs e) { Helpers.EnsureConfigurationDirectoryExistsOrThrow(e.XmlDocument.SelectElement("/iocConfiguration/appDataDir").GetAttribute("path")); // Lets explicitly set the DiManager to Autofac. Since we are going to test failure, the Di manager implementation does not matter. // However, this will give us predictability on what modules will be enabled. e.XmlDocument.SelectElement("/iocConfiguration/diManagers").SetAttributeValue(ConfigurationFileAttributeNames.ActiveDiManagerName, _diImplementationType.ToString()); }
public static (IContainerInfo containerInfo, IConfiguration configuration) LoadConfigurationFile(DiImplementationType diImplementationType, [NotNull] string configurationRelativePath, [CanBeNull] IDiModule[] additionalModulesToLoad = null, [CanBeNull] Action <XmlDocument> modifyConfigurationFileOnLoad = null) { TestsHelper.SetupLogger(); var ioCConfigurator = new DiContainerBuilder.DiContainerBuilder() .StartFileBasedDi( new FileBasedConfigurationParameters( new FileBasedConfigurationFileContentsProvider(Path.Combine(Helpers.TestsEntryAssemblyFolder, configurationRelativePath)), Helpers.TestsEntryAssemblyFolder, new LoadedAssembliesForTests()) { ConfigurationFileXmlDocumentLoaded = (sender, e) => { Helpers.EnsureConfigurationDirectoryExistsOrThrow(e.XmlDocument.SelectElement("/iocConfiguration/appDataDir").GetAttribute("path")); // Lets explicitly set the DiManager to Autofac. Since we are going to test failure, the Di manager implementation does not matter. // However, this will give us predictability on what modules will be enabled. e.XmlDocument.SelectElement("/iocConfiguration/diManagers").SetAttributeValue(ConfigurationFileAttributeNames.ActiveDiManagerName, diImplementationType.ToString()); modifyConfigurationFileOnLoad?.Invoke(e.XmlDocument); }, AttributeValueTransformers = new[] { new FileFolderPathAttributeValueTransformer() }, }, out _) .WithoutPresetDiContainer(); if (additionalModulesToLoad?.Length > 0) { ioCConfigurator.AddAdditionalDiModules(additionalModulesToLoad); } var containerInfo = ioCConfigurator.RegisterModules().Start(); return(containerInfo, containerInfo.DiContainer.Resolve <IConfiguration>()); }