Example #1
0
        /// <summary>
        /// Applys a json service metadata configuration file.
        /// </summary>
        /// <param name="container">A <c>Alioth.Framework.IAliothServiceContainer</c> will be applied.</param>
        /// <param name="reader">A <c>System.IO.Stream</c> that represents a metadata file.</param>
        /// <returns>A object of <c>Alioth.Framework.IAliothServiceContainer</c>.</returns>
        public static IAliothServiceContainer Apply(this IAliothServiceContainer container, StreamReader reader)
        {
            #region precondition
            if (reader == null)
            {
                throw new ArgumentNullException("path");
            }
            #endregion
            var json             = reader.ReadToEnd();
            var serviceContainer = JsonConvert.DeserializeObject <ServiceContainer>(json);
            foreach (var dep in serviceContainer.Services)
            {
#if DEBUG
                Type type = Type.GetType(dep.Type);
                container.Apply(type, dep.Parameters, dep.Properties, dep.Name, dep.Version);
#else
                try {
                    Type type = Type.GetType(dep.Type);
                    container.Apply(type, dep.Parameters, dep.Properties, dep.Name, dep.Version);
                } catch (TargetInvocationException tie) {
                    throw new Exception(String.Format("Type load failure, '{0}'", dep.Type), tie);
                } catch (ArgumentException ae) {
                    throw new Exception(String.Format("Type load failure, '{0}'", dep.Type), ae);
                } catch (TypeLoadException tle) {
                    throw new Exception(String.Format("Type load failure, '{0}'", dep.Type), tle);
                } catch (BadImageFormatException bfe) {
                    throw new Exception(String.Format("Type load failure, '{0}'", dep.Type), bfe);
                }
#endif
            }
            return(container);
        }
Example #2
0
 public void Connect(IAliothServiceContainer container)
 {
     #region precondition
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     #endregion
     this.container = container;
 }
        public Test_Alioth_Framework()

        {
            container = new AliothServiceContainer();
            using (Stream stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream($"{this.GetType().GetTypeInfo().Namespace}.servicecontainer.json"))

            {
                container.Apply(stream);
            }
        }
Example #4
0
 /// <summary>
 /// Applys a json service metadata configuration file.
 /// </summary>
 /// <param name="container">A <c>Alioth.Framework.IAliothServiceContainer</c> will be applied.</param>
 /// <param name="stream">A <c>System.IO.Stream</c> that represents a metadata file.</param>
 /// <returns>A object of <c>Alioth.Framework.IAliothServiceContainer</c>.</returns>
 public static IAliothServiceContainer Apply(this IAliothServiceContainer container, Stream stream)
 {
     #region precondition
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     #endregion
     return(container.Apply(new StreamReader(stream)));
 }
Example #5
0
        /// <summary>
        /// Applys a json service metadata configuration file.
        /// </summary>
        /// <param name="container">A <c>Alioth.Framework.IAliothServiceContainer</c> will be applied.</param>
        /// <param name="path">The path of the metadata file.</param>
        /// <returns>A object of <c>Alioth.Framework.IAliothServiceContainer</c>.</returns>
        public static IAliothServiceContainer Apply(this IAliothServiceContainer container, String path)
        {
            #region precondition
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (!File.Exists(path))
            {
#if NET451
                throw new FileNotFoundException("ContainerExtension.Apply: configuration file not be found.", path);
#elif DOTNET5_4
                throw new ArgumentException("ContainerExtension.Apply: configuration file not be found.", path);
#endif
            }
            #endregion
            using (StreamReader reader = File.OpenText(path)) {
                container.Apply(reader);
            }
            return(container);
        }
 public static IAliothServiceContainer Apply <T, O>(this IAliothServiceContainer container, O instance, String name, String version) where O : T
 {
     return(container.Apply <T, O>(instance, name, version));
 }
 public static IAliothServiceContainer Apply <T, O>(this IAliothServiceContainer container, O instance) where O : T
 {
     return(container.Apply <T, O>(instance, null, null));
 }
 public static IAliothServiceContainer Apply(this IAliothServiceContainer container, Type objectType, string name, string version)
 {
     return(container.Apply(objectType, null, null, name, version));
 }
 public static IAliothServiceContainer Apply(this IAliothServiceContainer container, Type objectType)
 {
     return(container.Apply(objectType, null, null, null, null));
 }
 /// <summary>
 /// Initializes a new instance of the class <c>Alioth.Framework.AliothServiceContainer</c> with a specified parent IoC container <paramref name="parent"/>.
 /// </summary>
 /// <param name="parent">The parent IoC cotnainer of the new IoC container.</param>
 public AliothServiceContainer(IAliothServiceContainer parent = null)
 {
     this.builderContainer = new ConcurrentDictionary <ServiceKey, IObjectBuilder>();
     this.parent           = parent;
 }