LinFu.IoC.ServiceContainer.Contains C# (CSharp) Method

Contains() public method

Determines whether or not the given serviceType can be instantiated by the container.
public Contains ( Type serviceType, IEnumerable additionalParameterTypes ) : bool
serviceType System.Type The type of service to instantiate.
additionalParameterTypes IEnumerable The list of additional parameters that this factory type will support.
return bool
        public virtual bool Contains(Type serviceType, IEnumerable<Type> additionalParameterTypes)
        {
            return Contains(null, serviceType, additionalParameterTypes);
        }

Same methods

ServiceContainer::Contains ( string serviceName, Type serviceType, IEnumerable additionalParameterTypes ) : bool

Usage Example

        public void ShouldLoadAssemblyIntoLoaderAtRuntime()
        {
            string path = Path.Combine(@"..\..\..\SampleFileWatcherLibrary\bin\Debug",
                                       AppDomain.CurrentDomain.BaseDirectory);
            string targetFile = "SampleFileWatcherLibrary.dll";
            string sourceFileName = Path.Combine(path, targetFile);

            var container = new ServiceContainer();
            container.AutoLoadFrom(AppDomain.CurrentDomain.BaseDirectory, "dummy.dll");

            // There should be nothing loaded at this point since the assembly hasn't
            // been copied to the target directory yet
            Assert.IsFalse(container.Contains(typeof (ISampleService)));

            // Copy the assembly to the target directory
            // and watch for changes
            string targetFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dummy.dll");
            File.Copy(sourceFileName, targetFileName, true);

            // Give the watcher thread enough time to load the assembly into memory
            Thread.Sleep(500);
            Assert.IsTrue(container.Contains(typeof (ISampleService)));

            var instance = container.GetService<ISampleService>();
            Assert.IsNotNull(instance);

            string typeName = instance.GetType().Name;
            Assert.AreEqual("SampleFileWatcherServiceClassAddedAtRuntime", typeName);
        }
All Usage Examples Of LinFu.IoC.ServiceContainer::Contains