Ejemplo n.º 1
0
        public void Configure(Action <ConfigurationExpression> configure)
        {
            var registry = new ConfigurationExpression();

            configure(registry);

            if (registry.HasPolicyChanges() && Role == ContainerRole.Nested)
            {
                throw new StructureMapConfigurationException("Policy changes to a nested container are not allowed. Policies can only be applied to the root container");
            }

            var builder = new PluginGraphBuilder(_pluginGraph);

            builder.Add(registry);

            registry.Registries.Each(x => x.As <IPluginGraphConfiguration>().Register(builder));
            registry.Registries.Each(x => builder.Add(x));

            builder.RunConfigurations();

            if (registry.HasPolicyChanges())
            {
                Instances.GetAllInstances().ToArray().Each(x => x.ClearBuildPlan());

                Profiles.AllProfiles().ToArray()
                .Each(x => x.Instances.GetAllInstances().ToArray().Each(i => i.ClearBuildPlan()));
            }
        }
Ejemplo n.º 2
0
        public void Dispose()
        {
            if (_wasDisposed)
            {
                return;
            }
            _wasDisposed = true;

            if (Role == ContainerRole.Root)
            {
                _singletons.DisposeAndClear();
            }

            ContainerCache.DisposeAndClear();


            _transients.DisposeAndClear();
            _pluginGraph.SafeDispose();

            if (Role == ContainerRole.Root)
            {
                _profiles.AllProfiles().Each(x => x.Dispose());
            }

            _trackedDisposables.Each(x => x.Dispose());
        }
Ejemplo n.º 3
0
        public void Configure(Action <ConfigurationExpression> configure)
        {
            if (_pluginGraph.IsRunningConfigure)
            {
                throw new StructureMapConfigurationException("The container is already being configured. Recursive IContainer.Configure() calls are not allowed");
            }

            _pluginGraph.IsRunningConfigure = true;

            try
            {
                var registry = new ConfigurationExpression();
                configure(registry);

                var transientTracking = registry.GetTransientTracking();
                if (transientTracking != null &&
                    transientTracking != _pluginGraph.TransientTracking)
                {
                    changeTransientTracking(transientTracking.Value);
                }

                if (registry.HasPolicyChanges() && Role == ContainerRole.Nested)
                {
                    throw new StructureMapConfigurationException("Policy changes to a nested container are not allowed. Policies can only be applied to the root container");
                }

                if (registry.HasPolicyChanges())
                {
                    _pluginGraph.ClearTypeMisses();
                }

                var builder = new PluginGraphBuilder(_pluginGraph);
                builder.Add(registry);

                registry.Registries.Each(x => builder.Add(x));

                builder.RunConfigurations();

                if (registry.HasPolicyChanges())
                {
                    Instances.GetAllInstances().ToArray().Each(x => x.ClearBuildPlan());

                    Profiles.AllProfiles().ToArray()
                    .Each(x => x.Instances.GetAllInstances().ToArray().Each(i => i.ClearBuildPlan()));
                }
            }
            finally
            {
                _pluginGraph.IsRunningConfigure = false;
            }
        }
Ejemplo n.º 4
0
        public void Configure(Action <ConfigurationExpression> configure)
        {
            var registry = new ConfigurationExpression();

            configure(registry);

            var builder = new PluginGraphBuilder(_pluginGraph);

            builder.Add(registry);

            registry.Registries.Each(x => x.As <IPluginGraphConfiguration>().Register(builder));
            registry.Registries.Each(x => builder.Add(x));

            builder.RunConfigurations();

            if (registry.HasPolicyChanges())
            {
                Instances.GetAllInstances().ToArray().Each(x => x.ClearBuildPlan());

                Profiles.AllProfiles().ToArray()
                .Each(x => x.Instances.GetAllInstances().ToArray().Each(i => i.ClearBuildPlan()));
            }
        }