private static string ReadXmlFromFile() { var fileName = UnityConfiguration.GetUnityConfigurationFileName(); var s = File.ReadAllText(fileName); var doc = new XmlDocument(); doc.LoadXml(s); var root = doc.GetElementsByTagName("unity")[0]; return(root.OuterXml); }
private static void WriteXmlToFile() { var callHandlerType = typeof(ICallHandler); var configuration = new UnityConfiguration(); configuration.OfXml(); foreach (var assembly in GetAssemblies()) { configuration.unity.AddAssembly(assembly.GetName().Name); } foreach (var type in GetTypes()) { configuration.unity.AddNamespace(type.Namespace); if (callHandlerType.IsAssignableFrom(type)) { continue; } foreach (MethodInfo m in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (!m.IsVirtual) { continue; } if (!m.IsPublic && !m.IsFamily) { continue; } foreach (var attribute in m.GetCustomAttributes(true)) { var aspectAttribute = attribute as UnityAspectAttribute; if (aspectAttribute == null) { continue; } configuration.unity.container.interception.AddPolicies(new Policy(type.FullName, m.Name, aspectAttribute.GetCallHandlerTypeName(), aspectAttribute.GetUnityProperties())); } } var register = new Register { type = type.Name }; var typeLifetime = GetLifetime(type); if (!string.IsNullOrWhiteSpace(typeLifetime)) { register.lifetime = new UnityLifeTimeItem { type = typeLifetime } } ; var mapOf = GetMapOf(type); if (!string.IsNullOrWhiteSpace(mapOf)) { register.type = mapOf; register.mapTo = type.Name; } if (configuration.unity.container.Registers.All(x => x.type != register.type)) { configuration.unity.container.Registers.Add(register); } } configuration.ToXml(); }