SetDefault() public method

Sets the default Instance.
public SetDefault ( StructureMap.Pipeline.Instance instance ) : void
instance StructureMap.Pipeline.Instance
return void
Example #1
0
        public PluginFamily Build(Type type)
        {
            if (type != typeof (IFancy)) return null;

            var family = new PluginFamily(type);
            family.SetDefault(new SmartInstance<Very>());

            return family;
        }
        public PluginFamily Build(Type type)
        {
            if (EnumerableInstance.IsEnumerable(type))
            {
                var family = new PluginFamily(type);
                family.SetDefault(new AllPossibleInstance(type));

                return family;
            }

            return null;
        }
Example #3
0
        public PluginFamily Build(Type type)
        {
            if (type.Name.EndsWith("Settings") && type.IsConcreteWithDefaultCtor())
            {
                var family = new PluginFamily(type);
                var instance = buildInstanceForType(type);
                family.SetDefault(instance);

                return family;
            }

            return null;
        }
        public PluginFamily Build(Type pluginType)
        {
            if (!pluginType.IsAbstract && pluginType.IsClass)
            {
                return null;
            }

            var family = new PluginFamily(pluginType);
            family.SetDefault(() => {
                var service = _locator.Service(pluginType);

                return new ObjectInstance(service);
            });

            return family;
        }
        PluginFamily IFamilyPolicy.Build(Type pluginType)
        {
            if (pluginType.IsConcrete())
            {
                return null;
            }

            var family = new PluginFamily(pluginType);

            var service = _locator.Service(pluginType);

            var instance = new ObjectInstance(service);

            family.SetDefault(instance);

            return family;
        }
Example #6
0
    public PluginFamily CreateTemplatedClone(Type[] templateTypes)
    {
        Type templatedType = _pluginType.MakeGenericType(templateTypes);
            var templatedFamily = new PluginFamily(templatedType);
            templatedFamily.copyLifecycle(this);

            _instances.GetAll().Select(x => {
                Instance clone = x.CloseType(templateTypes);
                if (clone == null) return null;

                clone.Name = x.Name;
                return clone;
            }).Where(x => x != null).Each(templatedFamily.AddInstance);

            if (GetDefaultInstance() != null)
            {
                string defaultKey = GetDefaultInstance().Name;
                Instance @default = templatedFamily.Instances.FirstOrDefault(x => x.Name == defaultKey);
                if (@default != null)
                {
                    templatedFamily.SetDefault(@default);
                }
            }

            //Are there instances that close the templatedtype straight away?
            _instances.GetAll()
                      .Where(x => x.ConcreteType.CanBeCastTo(templatedType))
                      .Each(templatedFamily.AddInstance);

            return templatedFamily;
    }