Example #1
0
        public void can_set_scope_directly_on_the_instance()
        {
            var i1 = new ConfiguredInstance(GetType()).Named("foo");
            i1.SetScopeTo(InstanceScope.ThreadLocal);

            i1.Lifecycle.ShouldBeOfType<ThreadLocalStorageLifecycle>();
        }
Example #2
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>();
        }
Example #3
0
        public void get_instance_if_the_object_is_unique_and_does_not_exist()
        {
            var instance = new ConfiguredInstance(typeof(Foo));
            instance.SetScopeTo(Lifecycles.Unique);

            var foo = new Foo();
            var foo2 = new Foo();

            theResolver.Stub(x => x.BuildNewInSession(typeof(IFoo), instance)).Return(foo).Repeat.Once();
            theResolver.Stub(x => x.BuildNewInSession(typeof(IFoo), instance)).Return(foo2).Repeat.Once();

            theCache.GetObject(typeof(IFoo), instance).ShouldBeTheSameAs(foo);
            theCache.GetObject(typeof(IFoo), instance).ShouldBeTheSameAs(foo2);
        }