AddInstance() public method

Add an additional Instance to this PluginFamily/PluginType
public AddInstance ( StructureMap.Pipeline.Instance instance ) : void
instance StructureMap.Pipeline.Instance
return void
コード例 #1
0
        public void FindMaster_Instance_happy_path()
        {
            var family = new PluginFamily(typeof (ISomething));
            ObjectInstance redInstance = new ObjectInstance(new SomethingOne()).WithName("Red");
            family.AddInstance(redInstance);
            family.AddInstance(new ObjectInstance(new SomethingOne()).WithName("Blue"));

            var instance = new ReferencedInstance("Red");
            Assert.AreSame(redInstance, ((IDiagnosticInstance) instance).FindInstanceForProfile(family, null, null));
        }
コード例 #2
0
        public void has_family_but_family_does_not_have_owner()
        {
            var family = new PluginFamily(GetType());
            var instance = new SimpleInstance();
            family.AddInstance(instance);

            instance.Owner().ShouldBeNull();
        }
コード例 #3
0
        public void still_chooses_PerRequest_if_nothing_is_selected_on_either_family_or_instance()
        {
            var family = new PluginFamily(GetType());

            var i1 = new ConfiguredInstance(GetType()).Named("foo");

            family.AddInstance(i1);

            i1.Lifecycle.ShouldBeOfType<TransientLifecycle>();
        }
コード例 #4
0
        public void Add_instance_that_does_not_exist_in_destination()
        {
            var source = new PluginFamily(typeof (IWidget));
            var sourceInstance = new ObjectInstance(new AWidget());
            source.AddInstance(sourceInstance);

            var destination = new PluginFamily(typeof (IWidget));
            destination.ImportFrom(source);

            Assert.AreSame(sourceInstance, destination.GetInstance(sourceInstance.Name));
        }
コード例 #5
0
        public void does_override_the_scope_of_the_parent()
        {
            var family = new PluginFamily(GetType());
            family.SetScopeTo(InstanceScope.Singleton);

            var i1 = new ConfiguredInstance(GetType()).Named("foo");
            i1.SetScopeTo(InstanceScope.ThreadLocal);

            family.AddInstance(i1);

            i1.Lifecycle.ShouldBeOfType<ThreadLocalStorageLifecycle>();
        }
コード例 #6
0
        public void Do_not_override_named_instance()
        {
            var source = new PluginFamily(typeof (IWidget));
            ObjectInstance sourceInstance = new ObjectInstance(new AWidget()).WithName("New");
            source.AddInstance(sourceInstance);

            var destination = new PluginFamily(typeof (IWidget));
            ObjectInstance destinationInstance = new ObjectInstance(new AWidget()).WithName("New");
            destination.AddInstance(destinationInstance);

            destination.ImportFrom(source);

            Assert.AreSame(destinationInstance, destination.GetInstance(sourceInstance.Name));
        }
コード例 #7
0
        public void Import_from_family_picks_up_new_instances()
        {
            var factory = new InstanceFactory(typeof (IWidget));

            var family = new PluginFamily(typeof (IWidget));
            family.AddInstance(new ObjectInstance(new AWidget()).WithName("New"));
            family.AddInstance(new ObjectInstance(new AWidget()).WithName("New2"));
            family.AddInstance(new ObjectInstance(new AWidget()).WithName("New3"));

            factory.ImportFrom(family);

            Assert.IsNotNull(factory.FindInstance("New"));
            Assert.IsNotNull(factory.FindInstance("New2"));
            Assert.IsNotNull(factory.FindInstance("New3"));
        }
コード例 #8
0
        public void Merge_from_PluginFamily_will_not_replace_an_existing_instance()
        {
            var factory = new InstanceFactory(typeof (IWidget));
            ObjectInstance instance1 = new ObjectInstance(new AWidget()).WithName("New");
            factory.AddInstance(instance1);

            var family = new PluginFamily(typeof (IWidget));
            family.AddInstance(new ObjectInstance(new AWidget()).WithName("New"));

            factory.ImportFrom(family);

            Assert.AreSame(instance1, factory.FindInstance("New"));
        }
コード例 #9
0
        public void uses_parent_lifecycle_if_none_is_set_on_instance()
        {
            var family = new PluginFamily(GetType());
            family.SetScopeTo(InstanceScope.Singleton);

            var i1 = new ConfiguredInstance(GetType()).Named("foo");

            family.AddInstance(i1);

            i1.Lifecycle.ShouldBeOfType<SingletonLifecycle>();
        }
コード例 #10
0
ファイル: FamilyParser.cs プロジェクト: hp4711/structuremap
 private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder)
 {
     familyElement.ForEachChild(INSTANCE_NODE).Do(element =>
     {
         InstanceMemento memento = _mementoCreator.CreateMemento(element);
         family.AddInstance(memento);
     });
 }