Пример #1
0
        /// <summary>
        /// Sets the factory used to create a container.
        /// </summary>
        /// <param name="factory">The container factory.</param>
        public static void SetContainerFactory(ICompositionContainerFactory factory)
        {
            Throw.IfArgumentNull(factory, "factory");

            mutex.WaitOne();

            if (initialised)
                return;

            try
            {
                var container = factory.CreateContainer();
                Throw.If(container == null).As<InvalidOperationException>(() => StringResources.FactoryDidntCreateContainer);

                Container = container;

                // Add the container to itself so it can be resolved.
                var batch = new CompositionBatch();
                batch.AddExportedValue(container);
                container.Compose(batch);

                initialised = true;
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
        /// <summary>
        /// Sets the composition container factory.
        /// </summary>
        /// <param name="factory">The container factory.</param>
        public static void SetCompositionContainerFactory(ICompositionContainerFactory factory)
        {
            if (factory == null)
                throw new ArgumentNullException("factory");

            lock (sync)
            {
                var provider = new ServiceHostExportProvider();
                _container = factory.CreateCompositionContainer(provider);

                provider.SourceContainer = _container;
            }
        }
Пример #3
0
        /// <summary>
        /// Initialises a new instance of <see cref="ServiceManager"/>.
        /// </summary>
        /// <param name="factory">The container factory.</param>
        public ServiceManager(ICompositionContainerFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            var provider = new ServiceHostExportProvider();

            _container = factory.CreateCompositionContainer(provider);
            _container.ComposeExportedValue(this);

            provider.SourceContainer = _container;
            Initialise();
        }
Пример #4
0
        /// <summary>
        /// Sets the factory used to create a container.
        /// </summary>
        /// <param name="factory">The container factory.</param>
        public static void SetContainerFactory(ICompositionContainerFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            mutex.WaitOne();

            if (initialised)
            {
                return;
            }

            try
            {
                var container = factory.CreateContainer();

                if (container == null)
                {
                    throw new InvalidOperationException("The container factory failed to create the container.");
                }

                Container = container;

                // Add the container to itself so it can be resolved.
                var batch = new CompositionBatch();
                batch.AddExportedValue(container);
                container.Compose(batch);

                initialised = true;
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
 public ComposedServiceManager(ICompositionContainerFactory factory) : base(factory)
 {
 }
        //protected void ConfigureDirectoryCatalog()
        //{
        //}

        protected void CreateContainerFactory()
        {
            _directoryCatalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory);
            _factory = new DelegateCompositionContainerFactory(ep => new CompositionContainer(this._directoryCatalog, ep));
        }
        //protected void ConfigureDirectoryCatalog()
        //{
        //}

        protected void CreateContainerFactory()
        {
            _directoryCatalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory);
            _factory          = new DelegateCompositionContainerFactory(ep => new CompositionContainer(this._directoryCatalog, ep));
        }