Exemplo n.º 1
0
        /// <summary>
        /// Registers a tracer instance for the child process, based on the arguments received from the parent process.
        /// </summary>
        /// <param name="container">The unity container</param>
        /// <param name="args">The command line arguments</param>
        /// <returns>The unity container, after registering the tracer instance</returns>
        public static IUnityContainer WithChildProcessTracer(this IUnityContainer container, string[] args)
        {
            // We need to use an instance of IChildProcessManager, just to create the tracer.
            // To overcome the "chicken and egg" problem, we use a child container.
            ITracer tracer;

            using (IUnityContainer childContainer = container.CreateChildContainer())
            {
                ITracer childTracer = new ConsoleTracer(string.Empty);
                childContainer.RegisterInstance(childTracer);
                IChildProcessManager childProcessManager = childContainer.Resolve <IChildProcessManager>();
                tracer = childProcessManager.CreateTracerForChildProcess(args);
            }

            // Now register the instance with the parent container
            container.RegisterInstance(tracer);
            return(container);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers dependencies for the child process, based on the arguments received from the parent process.
        /// </summary>
        /// <param name="container">The unity container</param>
        /// <param name="args">The command line arguments</param>
        /// <returns>The unity container, after registering the dependencies</returns>
        public static IUnityContainer WithChildProcessRegistrations(this IUnityContainer container, string[] args)
        {
            // We need to use an instance of IChildProcessManager, to parse the arguments.
            // To overcome the "chicken and egg" problem, we use a child container.
            IExtendedTracer      tracer;
            ISmartDetectorLoader loader;

            using (IUnityContainer childContainer = container.CreateChildContainer())
            {
                IExtendedTracer childTracer = new ConsoleTracer(string.Empty);
                childContainer.RegisterInstance(childTracer);
                IChildProcessManager childProcessManager = childContainer.Resolve <IChildProcessManager>();
                tracer = childProcessManager.CreateTracerForChildProcess(args);
                loader = childProcessManager.CreateLoaderForChildProcess(args, tracer);
            }

            // Now register the instances with the parent container
            container.RegisterInstance(tracer);
            container.RegisterInstance(loader);
            return(container);
        }