Пример #1
0
        public void ContainerShouldThrowExceptionWhenDisposed()
        {
            var container = new ObjectContainer();
            container.Dispose();

            container.Resolve<IObjectContainer>();
        }
Пример #2
0
        /// <summary>
        /// Disposes the data store, and if specified, also closes the data store and clears it from state.
        /// </summary>
        public void Dispose(bool fullDisposal)
        {
            if (fullDisposal)
            {
                // If the container is initialized
                if (IsContainerInitialized)
                {
                    // Roll back to the last commit
                    // This roll back is important. The data store must not commit the latest data unless commit call is explicit.
                    // If rollback is not called then the latest data will be automatically committed
                    // The ability to dispose without committing is necessary for unit testing, transactions, etc.
                    ObjectContainer.Rollback();
                    // TODO: Add a property to specify whether or not to automatically roll back

                    // Dispose the container
                    ObjectContainer.Dispose();
                }

                // Dispose the server
                if (IsServerInitialized)
                {
                    ObjectServer.Close();                     // ObjectServer must be closed to unlock files.
                    ObjectServer.Dispose();
                    ObjectServer = null;
                }

                StateAccess.State.SetApplication(ObjectContainerKey, null);
                StateAccess.State.SetApplication(ObjectServerKey, null);
            }
        }
Пример #3
0
        public void ContainerShouldThrowExceptionWhenDisposed()
        {
            var container = new ObjectContainer();

            container.Dispose();

            Assert.Throws <ObjectContainerException>(() => container.Resolve <IObjectContainer>(), "Object container disposed");
        }
Пример #4
0
        public void ContainerShouldThrowExceptionWhenDisposed()
        {
            var container = new ObjectContainer();

            container.Dispose();

            container.Resolve <IObjectContainer>();
        }
        public void ShouldNotDisposeFactoryWhenDispositionIsRequestedForANonDisposableFactory()
        {
            // given
            var container = new ObjectContainer();

            container.RegisterFactoryAs <IInterface1>(() => new SimpleClassWithDefaultCtor(), dispose: true);
            var obj = container.Resolve <IInterface1>();

            // when
            container.Dispose();
        }
Пример #6
0
        public void ShouldDisposeCreatedObjects()
        {
            var container = new ObjectContainer();
            container.RegisterTypeAs<DisposableClass1, IDisposableClass>();

            var obj = container.Resolve<IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeTrue();
        }
Пример #7
0
        public void ShouldNotCauseAnErrorWhenRequestingDispositionForANonDisposableInstance()
        {
            var container = new ObjectContainer();
            var obj       = new SimpleClassWithDefaultCtor();

            container.RegisterInstanceAs <IInterface1>(obj, dispose: true);

            container.Resolve <IInterface1>();

            container.Dispose();
        }
        public void ShouldNotAttemptToReleaseANonDisposableFactory()
        {
            // given
            var container  = new ObjectContainer();
            var dependency = new VerySimpleClass();

            container.RegisterFactoryAs <IInterface1>(() => new VerySimpleClass());
            var obj = container.Resolve <IInterface1>();

            // when
            container.Dispose();
        }
Пример #9
0
        public void ShouldDisposeCreatedObjects()
        {
            var container = new ObjectContainer();

            container.RegisterTypeAs <DisposableClass1, IDisposableClass>();

            var obj = container.Resolve <IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeTrue();
        }
Пример #10
0
        public void ShouldNotDisposeObjectsRegisteredAsInstance()
        {
            var container = new ObjectContainer();
            var obj = new DisposableClass1();
            container.RegisterInstanceAs<IDisposableClass>(obj);

            container.Resolve<IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeFalse();
        }
Пример #11
0
        public void ShouldDisposeInstanceRegistrations()
        {
            var container = new ObjectContainer();
            var obj = new DisposableClass1();
            container.RegisterInstanceAs<IDisposableClass>(obj, dispose: true);

            container.Resolve<IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeTrue();
        }
Пример #12
0
        public void ShouldDisposeInstanceRegistrations()
        {
            var container = new ObjectContainer();
            var obj       = new DisposableClass1();

            container.RegisterInstanceAs <IDisposableClass>(obj, dispose: true);

            container.Resolve <IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeTrue();
        }
Пример #13
0
        public void ShouldNotDisposeObjectsFromBaseContainer()
        {
            var baseContainer = new ObjectContainer();
            baseContainer.RegisterTypeAs<DisposableClass1, IDisposableClass>();
            var container = new ObjectContainer(baseContainer);

            baseContainer.Resolve<IDisposableClass>();
            var obj = container.Resolve<IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeFalse();
        }
Пример #14
0
        public void ShouldNotDisposeObjectsRegisteredAsInstance()
        {
            var container = new ObjectContainer();
            var obj       = new DisposableClass1();

            container.RegisterInstanceAs <IDisposableClass>(obj);

            container.Resolve <IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeFalse();
        }
        public void ShouldDisposeFactoryWhenRequested()
        {
            // given
            var container = new ObjectContainer();

            container.RegisterFactoryAs <IDisposableClass>(() => new DisposableClass1(), dispose: true);
            var obj = container.Resolve <IDisposableClass>();

            // when
            container.Dispose();

            // then
            Assert.IsTrue(obj.WasDisposed);
        }
        public void ShouldNotDisposeFactoryWhenDispositionIsntRequested()
        {
            // given
            var container = new ObjectContainer();

            container.RegisterFactoryAs <IDisposableClass>(() => new DisposableClass1(), dispose: false);
            var obj = container.Resolve <IDisposableClass>();

            // when
            container.Dispose();

            // then
            obj.WasDisposed.ShouldBeFalse();
        }
Пример #17
0
        public void ShouldNotDisposeObjectsFromBaseContainer()
        {
            var baseContainer = new ObjectContainer();

            baseContainer.RegisterTypeAs <DisposableClass1, IDisposableClass>();
            var container = new ObjectContainer(baseContainer);

            baseContainer.Resolve <IDisposableClass>();
            var obj = container.Resolve <IDisposableClass>();

            container.Dispose();

            obj.WasDisposed.ShouldBeFalse();
        }
Пример #18
0
        public void SimpleStringSearch()
        {
//            _path = @"c:\test.yap";
//            ObjectContainer x = OpenDb();
//            DoSodaQuery(x, "96");
//            DoNativeQuery(x, "99");
//            DoNativeQuery(x, "88");
//            x.Dispose();

            MakeDatabase();

            ObjectContainer db = OpenDb();

            FindFormNQ(db, "99");
            FindFormNQ(db, "88");
            db.Dispose();

            db = OpenDb();
            FindFormSODA(db, "96");
            FindFormNQ(db, "87");
            db.Dispose();

            db = OpenDb();
            FindEntryNoArraySODA(db, "87");
            db.Dispose();

            db = OpenDb();
            FindEntryNoArrayNQ(db, "87");
            db.Dispose();

            db = OpenDb();
            FindEntryWithArrayNQ(db, "83");
            db.Dispose();

            File.Delete(_path);
        }
Пример #19
0
        public void Windsor_scope_ends_when_scenario_ends()
        {
            var globalContainer   = new ObjectContainer();
            var scenarioContainer = new ObjectContainer(globalContainer);

            CreateContainerViaPlugin(globalContainer, scenarioContainer);

            var activeScope = CallContextLifetimeScope.ObtainCurrentScope();

            scenarioContainer.Dispose();
            var endedScope = CallContextLifetimeScope.ObtainCurrentScope();

            activeScope.Should().NotBeNull();
            endedScope.Should().BeNull();
        }
        public void ShouldNotAttemptToDisposeFactoryMoreThanOnce()
        {
            // given
            var container  = new ObjectContainer();
            var dependency = new VerySimpleClass();
            var instance   = new OneTimeDisposableClass1();

            container.RegisterFactoryAs <IDisposableClass>(() => instance, dispose: true);
            var obj = container.Resolve <IDisposableClass>();

            obj = container.Resolve <IDisposableClass>();

            // when
            container.Dispose();

            // then
            obj.WasDisposed.ShouldBeTrue();
        }
 /// <summary>
 /// Releases all resource used by the <see cref="T:BoDi.Internal.DynamicResolutionObjectContainerProxy"/> object.
 /// </summary>
 /// <remarks>Call <see cref="Dispose"/> when you are finished using the
 /// <see cref="T:BoDi.Internal.DynamicResolutionObjectContainerProxy"/>. The <see cref="Dispose"/> method leaves the
 /// <see cref="T:BoDi.Internal.DynamicResolutionObjectContainerProxy"/> in an unusable state. After calling
 /// <see cref="Dispose"/>, you must release all references to the
 /// <see cref="T:BoDi.Internal.DynamicResolutionObjectContainerProxy"/> so the garbage collector can reclaim the
 /// memory that the <see cref="T:BoDi.Internal.DynamicResolutionObjectContainerProxy"/> was occupying.</remarks>
 public void Dispose()
 {
     proxiedContainer.Dispose();
 }