public void WhenRegistrationsAreMadeTheyDoNotAffectTheReadRegistry()
        {
            var read = new ComponentRegistry();
            var cow = new CopyOnWriteRegistry(read, () => new ComponentRegistry());
            var registration = RegistrationBuilder.ForType<object>().CreateRegistration();
            cow.Register(registration);

            var objectService = new TypedService(typeof (object));
            Assert.True(cow.IsRegistered(objectService));
            Assert.False(read.IsRegistered(objectService));
        }
        public void WhenReadingTheWriteRegistryIsNotCreated()
        {
            var writeRegistryCreated = false;
            var read = new ComponentRegistry();
            var cow = new CopyOnWriteRegistry(read, () =>
            {
                writeRegistryCreated = true;
                return new ComponentRegistry();
            });

            IComponentRegistration unused;
            cow.TryGetRegistration(new TypedService(typeof (object)), out unused);

            Assert.False(writeRegistryCreated);
        }
示例#3
0
 /// <summary>
 /// Begin a new tagged sub-scope. Instances created via the sub-scope
 /// will be disposed along with it.
 /// </summary>
 /// <param name="tag">The tag applied to the <see cref="ILifetimeScope"/>.</param>
 /// <returns>A new lifetime scope.</returns>
 public ILifetimeScope BeginLifetimeScope(object tag)
 {
     CheckNotDisposed();
     var registry = new CopyOnWriteRegistry(_componentRegistry, () => CreateScopeRestrictedRegistry(tag, NoConfiguration));
     var scope = new LifetimeScope(registry, this, tag);
     RaiseBeginning(scope);
     return scope;
 }