diff --git a/Source/Services/AppDomainTypeLister.Test.cs b/Source/Services/AppDomainTypeLister.Test.cs
deleted file mode 100644
index cdd0da1..0000000
--- a/Source/Services/AppDomainTypeLister.Test.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if UNITTEST
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using NUnit.Framework;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Unit Test for the cached app domain type lister
- [TestFixture]
- public class AppDomainTypeListerTest {
-
- ///
- /// Verifies that the assembly type list is generated correctly for
- /// the default constructor (using the calling app domain)
- ///
- [Test]
- public void TestDefaultConstructur() {
- AppDomainTypeLister testLister = new AppDomainTypeLister();
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(AppDomainTypeListerTest)).And.Member(typeof(Assembly))
- );
- }
-
- ///
- /// Verifies that the assembly type list is generated correctly for
- /// the full constructor
- ///
- [Test]
- public void TestFullConstructur() {
- AppDomain newAppDomain = AppDomain.CreateDomain("AppDomainTypeListerTest.Domain");
- try {
- AppDomainTypeLister testLister = new AppDomainTypeLister(newAppDomain);
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(Assembly)).And.No.Member(typeof(AppDomainTypeListerTest))
- );
- }
- finally {
- AppDomain.Unload(newAppDomain);
- }
- }
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
-
-#endif // UNITTEST
diff --git a/Source/Services/AppDomainTypeLister.cs b/Source/Services/AppDomainTypeLister.cs
deleted file mode 100644
index 876cbaa..0000000
--- a/Source/Services/AppDomainTypeLister.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
-#if WINDOWS
-
- /// Lists the types of all assemblies in an application domain
- public class AppDomainTypeLister : MultiAssemblyTypeLister {
-
- ///
- /// Initializes a new application domain type lister using the application domain
- /// of the calling method
- ///
- public AppDomainTypeLister() : this(AppDomain.CurrentDomain) { }
-
- /// Initializes a new application domain type lister
- /// Application domain whose types will be listed
- public AppDomainTypeLister(AppDomain appDomain) {
- this.appDomain = appDomain;
- }
-
- ///
- /// Obtains an enumerable list of all assemblies in the application domain
- ///
- /// An enumerable list of the assemblies in the application domain
- protected override IEnumerable GetAssemblies() {
- return this.appDomain.GetAssemblies();
- }
-
- /// Application domain whose types the lister works on
- private AppDomain appDomain;
-
- }
-
-#endif // WINDOWS
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ExplicitTypeLister.Test.cs b/Source/Services/ExplicitTypeLister.Test.cs
deleted file mode 100644
index 4ff1723..0000000
--- a/Source/Services/ExplicitTypeLister.Test.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if UNITTEST
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using NUnit.Framework;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Unit Test for the predefined type lister
- [TestFixture]
- public class ExplicitTypeListerTest {
-
- ///
- /// Verifies that the type lister correctly takes over a list of types
- /// supplied manually to the constructor
- ///
- [Test]
- public void TestPredefinedTypesFromParams() {
- ITypeLister testLister = new ExplicitTypeLister(
- typeof(ExplicitTypeListerTest), typeof(TestAttribute)
- );
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(ExplicitTypeListerTest)).And.Member(typeof(TestAttribute))
- );
- }
-
- ///
- /// Verifies that the type lister correctly takes over a list of types
- /// supplied as an enumerable list to the constructor
- ///
- [Test]
- public void TestPredefinedTypesFromEnumerable() {
- IEnumerable types = typeof(ExplicitTypeListerTest).Assembly.GetTypes();
- ITypeLister testLister = new ExplicitTypeLister(types);
-
- Assert.That(
- testLister.GetTypes(), Has.Member(typeof(ExplicitTypeListerTest))
- );
- }
-
- ///
- /// Verifies that types can be removed from the type lister
- ///
- [Test]
- public void TestRemoveTypesFromLister() {
- ExplicitTypeLister testLister = new ExplicitTypeLister(
- typeof(ExplicitTypeListerTest).Assembly.GetTypes()
- );
-
- Assert.That(
- testLister.GetTypes(), Has.Member(typeof(ExplicitTypeListerTest))
- );
- testLister.Types.Remove(typeof(ExplicitTypeListerTest));
- Assert.That(
- testLister.GetTypes(), Has.No.Member(typeof(ExplicitTypeListerTest))
- );
- }
-
- ///
- /// Verifies that types can be added to the type lister
- ///
- [Test]
- public void TestAddTypesToLister() {
- ExplicitTypeLister testLister = new ExplicitTypeLister();
-
- Assert.That(
- testLister.GetTypes(), Has.No.Member(typeof(TestAttribute))
- );
- testLister.Types.Add(typeof(TestAttribute));
- Assert.That(
- testLister.GetTypes(), Has.Member(typeof(TestAttribute))
- );
- }
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
-
-#endif // UNITTEST
diff --git a/Source/Services/ExplicitTypeLister.cs b/Source/Services/ExplicitTypeLister.cs
deleted file mode 100644
index bcbb9db..0000000
--- a/Source/Services/ExplicitTypeLister.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Type lister that returns a predefined list of types
- public class ExplicitTypeLister : ITypeLister {
-
- /// Initializes a new predefined type lister
- /// Types the predefined type lister will list
- public ExplicitTypeLister(params Type[] types) {
- this.types = new List(types);
- }
-
- /// Initializes a new predefined type lister
- /// Types the predefined type lister will list
- public ExplicitTypeLister(IEnumerable types) {
- this.types = new List(types);
- }
-
- ///
- /// Returns an enumerable list of types that will be checked by the service manager
- ///
- /// An enumerable list of types for the service manager
- public IEnumerable GetTypes() {
- return this.types;
- }
-
- /// Predefined list of types the lister will list
- public List Types {
- get { return this.types; }
- }
-
- /// The predefined list of types
- private List types;
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ITypeLister.cs b/Source/Services/ITypeLister.cs
deleted file mode 100644
index cb93fbf..0000000
--- a/Source/Services/ITypeLister.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using Nuclex.Support.Plugins;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- ///
- /// Provides a type list the service manager uses to locate components
- ///
- public interface ITypeLister {
-
- ///
- /// Returns an enumerable list of types that will be checked by the service manager
- ///
- /// An enumerable list of types for the service manager
- IEnumerable GetTypes();
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/Instancing.cs b/Source/Services/Instancing.cs
deleted file mode 100644
index b8036b3..0000000
--- a/Source/Services/Instancing.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-
-using Nuclex.Support.Plugins;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Modes in which services can be instantiated
- public enum Instancing {
-
- /// Disallow any service from being created for a contract
- Never,
-
- /// There will only be one service in the whole process
- Singleton,
-
- /// Each thread will be assigned its own service
- InstancePerThread,
-
- /// A new service will be created each time it is queried for
- Factory
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/MultiAssemblyTypeLister.Test.cs b/Source/Services/MultiAssemblyTypeLister.Test.cs
deleted file mode 100644
index 83f85e4..0000000
--- a/Source/Services/MultiAssemblyTypeLister.Test.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if UNITTEST
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using NUnit.Framework;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Unit Test for the cached assembly type lister
- [TestFixture]
- public class MultiAssemblyTypeListerTest {
-
- #region class TestAssemblyTypeLister
-
- /// Test implementation of a cached assembly type lister
- private class TestAssemblyTypeLister : MultiAssemblyTypeLister {
-
- /// Initializes a new test assembly type lister
- /// Assemblies whose types will be listed
- public TestAssemblyTypeLister(params Assembly[] assemblies) {
- ReplaceAssemblyList(assemblies);
- }
-
- /// Replaces the list of assemblies whose types to list
- /// Assemblies whose types will be listed
- public void ReplaceAssemblyList(params Assembly[] assemblies) {
- this.assemblies = assemblies;
- }
-
- /// Obtains a list of any assemblies whose types should be listed
- /// A list of any assemblies whose types to list
- protected override IEnumerable GetAssemblies() {
- return this.assemblies;
- }
-
- /// Assemblies whose types the test assembly type lister lists
- private Assembly[] assemblies;
-
- }
-
- #endregion // class TestAssemblyTypeLister
-
- ///
- /// Verifies that the assembly type list is generated correctly
- ///
- [Test]
- public void TestAssemblyListGeneration() {
- TestAssemblyTypeLister testLister = new TestAssemblyTypeLister(
- typeof(MultiAssemblyTypeListerTest).Assembly
- );
-
- Assert.That(
- testLister.GetTypes(), Has.Member(typeof(MultiAssemblyTypeListerTest))
- );
- }
-
- ///
- /// Verifies that the assembly type list is updated when list of assemblies
- /// changes inbetween calls
- ///
- [Test]
- public void TestAssemblyListReplacement() {
- TestAssemblyTypeLister testLister = new TestAssemblyTypeLister(
- typeof(Assembly).Assembly,
- typeof(TestAttribute).Assembly
- );
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(TestAttribute)).And.Not.Member(typeof(MultiAssemblyTypeListerTest))
- );
-
- testLister.ReplaceAssemblyList(
- typeof(Assembly).Assembly,
- typeof(MultiAssemblyTypeListerTest).Assembly
- );
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(MultiAssemblyTypeListerTest)).And.Not.Member(typeof(TestAttribute))
- );
- }
-
- ///
- /// Verifies that the assembly type list is updated when an assembly is removed
- /// from the list inbetween calls
- ///
- [Test]
- public void TestAssemblyListRemoval() {
- TestAssemblyTypeLister testLister = new TestAssemblyTypeLister(
- typeof(Assembly).Assembly,
- typeof(TestAttribute).Assembly,
- typeof(MultiAssemblyTypeListerTest).Assembly
- );
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(TestAttribute)).And.Member(typeof(MultiAssemblyTypeListerTest))
- );
-
- testLister.ReplaceAssemblyList(
- typeof(Assembly).Assembly,
- typeof(MultiAssemblyTypeListerTest).Assembly
- );
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(MultiAssemblyTypeListerTest)).And.Not.Member(typeof(TestAttribute))
- );
- }
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
-
-#endif // UNITTEST
-
diff --git a/Source/Services/MultiAssemblyTypeLister.cs b/Source/Services/MultiAssemblyTypeLister.cs
deleted file mode 100644
index 9684ad4..0000000
--- a/Source/Services/MultiAssemblyTypeLister.cs
+++ /dev/null
@@ -1,166 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Lists all types in a changing set of assemblies
- public abstract class MultiAssemblyTypeLister : ITypeLister {
-
- #region class AssemblyTypes
-
- /// Caches the list of types types for an assembly
- private class AssemblyTypes {
-
- /// Initializes a new cached assembly types list
- /// Assembly the types are found in
- /// Types defined in the assembly
- public AssemblyTypes(Assembly assembly, Type[] types) {
- this.Assembly = assembly;
- this.Types = types;
- }
-
- /// Assembly the types are found in
- public Assembly Assembly;
- /// Types defined in the assembly
- public Type[] Types;
-
- }
-
- #endregion // class AssemblyTypes
-
- /// Initializes a new assembly type lister
- public MultiAssemblyTypeLister() {
- this.assemblyTypes = new LinkedList();
- }
-
- /// Enumerates all types in the lister's assembly set
- /// An enumerator over all types in the lister's assembly set
- public IEnumerable GetTypes() {
-
- // Make sure the assembly list is filled and up-to-date
- if(this.assemblyTypes.Count == 0) {
- enlistAssembliesFirstTime();
- } else {
- updateAssemblyList();
- }
-
- // Iterate over all types in all assemblies
- LinkedListNode node = this.assemblyTypes.First;
- while(node != null) {
- Type[] types = node.Value.Types;
- for(int index = 0; index < types.Length; ++index) {
- yield return types[index];
- }
-
- node = node.Next;
- }
-
- }
-
- /// Called when the assemblies set is queried for the first time
- private void enlistAssembliesFirstTime() {
- foreach(Assembly assembly in GetAssemblies()) {
- this.assemblyTypes.AddLast(new AssemblyTypes(assembly, assembly.GetTypes()));
- }
- }
-
- /// Called to update the assembly list if it has changed
- private void updateAssemblyList() {
- LinkedListNode node = this.assemblyTypes.First;
-
- foreach(Assembly assembly in GetAssemblies()) {
-
- // If we reached the end of the cache, this automatically becomes a new entry
- if(node == null) {
- this.assemblyTypes.AddLast(new AssemblyTypes(assembly, assembly.GetTypes()));
- } else { // Otherwise, figure out whether the assembly list has changed
-
- // Try to locate the cached entry for this assembly. If we have to skip entries,
- // we know that an assembly might have been removed from the set. This will be
- // handled by moved all matched assemblies to the beginning, so that when we
- // finish, the assemblies after the last checked one automatically become those
- // which are no longer in the set.
- LinkedListNode existingNode = node;
- while(existingNode.Value.Assembly != assembly) {
- existingNode = existingNode.Next;
- if(existingNode == null) {
- break;
- }
- }
-
- // Is this assembly not yet in the cache?
- if(existingNode == null) {
-
- // If this assembly wasn't found in the cache, add it in the same order
- // it was returned by the enumerator. This will improve efficiency later
- // since the update algorithm is designed to perform optimally if the order
- // remains the same between calls.
- this.assemblyTypes.AddBefore(
- node, new AssemblyTypes(assembly, assembly.GetTypes())
- );
-
- } else if(existingNode != node) { // Did we skip other cached assemblies?
-
- // If other cached assemblies had to be skipped, this indicates that
- // the set of assemblies has changed. Move the list nodes to the same order
- // in which the assemblies are returned by the enumerator. Any cached
- // assemblies that have been completely removed from the set will therefore
- // end up at the bottom of the list after the update has completed.
- this.assemblyTypes.Remove(existingNode);
- this.assemblyTypes.AddBefore(node, existingNode);
-
- } else { // Assembly was found in the expected place
-
- // If the assembly was found in the same place as it was found during
- // the last check, the assembly list is unchanged at this entry.
- node = node.Next;
-
- }
- }
-
- }
-
- // Any nodes behind the last checked node contain cached type lists for assemblies
- // that are no longer in the set, so these will be removed.
- while(node != null) {
- LinkedListNode nextNode = node.Next;
- this.assemblyTypes.Remove(node);
- node = nextNode;
- }
- }
-
- /// Obtains a list of any assemblies whose types should be listed
- /// A list of any assemblies whose types to list
- protected abstract IEnumerable GetAssemblies();
-
- /// Cached assembly type lists
- private LinkedList assemblyTypes;
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ProgressTracking/IProgressCollectingService.cs b/Source/Services/ProgressTracking/IProgressCollectingService.cs
deleted file mode 100644
index 33a5339..0000000
--- a/Source/Services/ProgressTracking/IProgressCollectingService.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if ENABLE_SERVICEMANAGER
-
-using System;
-using System.Collections.Generic;
-
-using Nuclex.Support.Tracking;
-
-namespace Nuclex.Support.Services.ProgressTracking {
-
- /// Allows application-wide tracking of progress
- interface IProgressCollectingService {
-
- /// Tracks the progress of the specified transaction
- ///
- /// Transaction whose progress will be tracked
- ///
- ///
- /// Identifier unique to the tracked background process. Can be null.
- ///
- ///
- ///
- /// Using the process identifier allows you to track the progress of multiple
- /// transactions that are working independently of each other. This could,
- /// for example, result in multiple progress bars being displayed in a GUI.
- /// The global progress always is a combination of all transactions tracked
- /// by the service.
- ///
- ///
- /// A good analogy for this might be a download manager which uses several
- /// threads to download multiple sections of a file at the same time. You
- /// want a progress bar per file, but not one for each downloading thread.
- /// Specifying the name object as a process identifer, all transactions
- /// belonging to the same file would be merged into a single progress source.
- ///
- ///
- /// The process identifier can be a string or any object. Note however that
- /// as common practice, this object's ToString() method should return
- /// something reasonable, like "Downloading xy.txt". Localization can be
- /// achieved by implementing an interface (eg. ILocalizableToString) which
- /// provides a string and some parameters - or you could return the already
- /// translated versions of the string if you prefer to have localized versions
- /// of internal assemblies.
- ///
- ///
- void Track(Transaction transaction, object processIdentifier);
-
- /// Tracks the progress of the specified transaction
- ///
- /// Transaction whose progress will be tracked
- ///
- ///
- /// Tracks the transaction as if it was added with the process identifier
- /// set to null.
- ///
- void Track(Transaction transaction);
-
- /// Stops tracking the specified transaction
- /// Transaction that will no longer be tracked
- ///
- /// Untracking a transaction is optional. The service will automatically
- /// remove finished transactions from its list of tracked transactions. Calling
- /// this method is only required if you drop a transaction in a way that
- /// prevents its AsyncEnded event from being fired (eg. by not executing it
- /// at all, dispite adding it to the progress tracking service).
- ///
- void Untrack(Transaction transaction);
-
- }
-
-} // namespace Nuclex.Support.DependencyInjection.ProgressTracking
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ProgressTracking/IProgressPublishingService.cs b/Source/Services/ProgressTracking/IProgressPublishingService.cs
deleted file mode 100644
index 26cc70a..0000000
--- a/Source/Services/ProgressTracking/IProgressPublishingService.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if ENABLE_SERVICEMANAGER
-
-using System;
-using System.Collections.Generic;
-
-using Nuclex.Support.Tracking;
-
-namespace Nuclex.Support.Services.ProgressTracking {
-
- /// Reports the progress of tracked background processes
- ///
- ///
- /// This service is intended for the consumer of progress reports. It will notify
- /// subscribers when background processes start, when progress is achieved and
- /// when they finish.
- ///
- ///
- /// Usually, this interface, together with the IProgressTrackingService interface,
- /// is provided by a single service component that tracks the progress of
- /// transactions taking place asynchronously and reports it back this way.
- ///
- ///
- interface IProgressPublishingService {
-
- /// Fired when the overall progress changes
- event EventHandler ProgressChanged;
-
- /// The overall progress of all tracked background processes
- float TotalProgress { get; }
-
- /// Currently active background processes
- IEnumerable TrackedProcesses { get; }
-
- }
-
-} // namespace Nuclex.Support.DependencyInjection.ProgressTracking
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ProgressTracking/ITrackedProcess.cs b/Source/Services/ProgressTracking/ITrackedProcess.cs
deleted file mode 100644
index d4d5526..0000000
--- a/Source/Services/ProgressTracking/ITrackedProcess.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if ENABLE_SERVICEMANAGER
-
-using System;
-using System.Collections.Generic;
-
-using Nuclex.Support.Tracking;
-
-namespace Nuclex.Support.Services.ProgressTracking {
-
- /// Process whose progress is being tracked
- public interface ITrackedProcess {
-
- /// Fired whenever the progress of the process changes
- event EventHandler ProgressChanged;
-
- /// Unique identifier of the overall process
- ///
- /// As a convention, using this object's ToString() method should return
- /// something usable, either a string that can be displayed in the user
- /// interface or, depending on your architecture, the object could
- /// implement certain interfaces that allow a localized version of
- /// the string to be created.
- ///
- object ProcessIdentifier { get; }
-
- /// Progress that process has achieved so far
- float CurrentProgress { get; }
-
- }
-
-} // namespace Nuclex.Support.DependencyInjection.ProgressTracking
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ProgressTracking/ProgressTrackingComponent.cs b/Source/Services/ProgressTracking/ProgressTrackingComponent.cs
deleted file mode 100644
index 6e1506e..0000000
--- a/Source/Services/ProgressTracking/ProgressTrackingComponent.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if ENABLE_SERVICEMANAGER
-
-using System;
-using System.Collections.Generic;
-
-using Nuclex.Support.Tracking;
-
-namespace Nuclex.Support.Services.ProgressTracking {
-
- /// Tracks the progress of running background processes
- public class ProgressTrackingComponent :
- IProgressCollectingService,
- IProgressPublishingService {
-
- /// Fired when the overall progress changes
- public event EventHandler ProgressChanged;
-
- /// Initializes a new progress tracking component
- public ProgressTrackingComponent() {
- }
-
- /// Tracks the progress of the specified transaction
- ///
- /// Transaction whose progress will be tracked
- ///
- ///
- /// Identifier unique to the tracked background process. Can be null.
- ///
- public void Track(Transaction transaction, object processIdentifier) {
- }
-
- /// Tracks the progress of the specified transaction
- ///
- /// Transaction whose progress will be tracked
- ///
- public void Track(Transaction transaction) {
- }
-
- /// Stops tracking the specified transaction
- /// Transaction that will no longer be tracked
- public void Untrack(Transaction transaction) {
- }
-
- /// The overall progress of all tracked background processes
- public float TotalProgress {
- get { return 0.0f; }
- }
-
- /// Currently active background processes
- public IEnumerable TrackedProcesses {
- get { return null; }
- }
-
- }
-
-} // namespace Nuclex.Support.Services.ProgressTracking
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/RepositoryTypeLister.Test.cs b/Source/Services/RepositoryTypeLister.Test.cs
deleted file mode 100644
index 1108bcb..0000000
--- a/Source/Services/RepositoryTypeLister.Test.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if UNITTEST
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using NUnit.Framework;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Unit Test for the cached assembly repository type lister
- [TestFixture]
- public class RepositoryTypeListerTest {
-
- ///
- /// Tests whether the repository lister can cope with an empty repository
- ///
- [Test]
- public void TestEmptyLister() {
- RepositoryTypeLister testLister = new RepositoryTypeLister();
-
- Assert.That(testLister.GetTypes(), Is.Empty);
- }
-
- ///
- /// Tests whether the repository lister notices an updated repository
- ///
- [Test]
- public void TestLateAdd() {
- RepositoryTypeLister testLister = new RepositoryTypeLister();
- testLister.Repository.AddAssembly(typeof(RepositoryTypeListerTest).Assembly);
-
- Assert.That(
- testLister.GetTypes(),
- Has.Member(typeof(RepositoryTypeListerTest))
- );
- }
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
-
-#endif // UNITTEST
diff --git a/Source/Services/RepositoryTypeLister.cs b/Source/Services/RepositoryTypeLister.cs
deleted file mode 100644
index 648ab5d..0000000
--- a/Source/Services/RepositoryTypeLister.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using Nuclex.Support.Plugins;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- ///
- /// Lists the types of all assemblies contained in an assembly repository
- ///
- public class RepositoryTypeLister : MultiAssemblyTypeLister {
-
- ///
- /// Initializes a new repository type lister using a new repository
- ///
- public RepositoryTypeLister() : this(new PluginRepository()) { }
-
- ///
- /// Initializes a new repository type lister using an existing repository
- ///
- ///
- /// Repository containing the assemblies whose types will be listed
- ///
- public RepositoryTypeLister(PluginRepository repository) {
- this.repository = repository;
- }
-
- ///
- /// Returns an enumerable list of the assemblies in the repository
- ///
- /// An enumerable list of the assemblies in the repository
- protected override IEnumerable GetAssemblies() {
- return this.repository.LoadedAssemblies;
- }
-
- ///
- /// The assembly repository containing the assemblies whose types the lister
- /// operates on.
- ///
- public PluginRepository Repository {
- get { return this.repository; }
- }
-
- ///
- /// Repository containing the assemblies with the type lister's types
- ///
- private PluginRepository repository;
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ServiceManager.Analyzer.cs b/Source/Services/ServiceManager.Analyzer.cs
deleted file mode 100644
index 9dfacc4..0000000
--- a/Source/Services/ServiceManager.Analyzer.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- partial class ServiceManager {
-
- #region class Analyzer
-
- /// Analyzes Component dependencies
- private static class Analyzer {
-
-
-
- public static KeyValuePair[] GetRequirements(ConstructorInfo constructor) {
- ParameterInfo[] parameters = constructor.GetParameters();
- //parameters[0].IsOptional
-
- return null;
- }
-
- }
-
- #endregion // class Analyzer
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ServiceManager.For.cs b/Source/Services/ServiceManager.For.cs
deleted file mode 100644
index 63e8961..0000000
--- a/Source/Services/ServiceManager.For.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- partial class ServiceManager {
-
- #region class ForContext
-
- /// Manages the context of the "For" modifier
- public class ForContext {
-
- /// Initializes a new "For" context of the service manager
- /// Service manager the context operates on
- /// Contract that is being modified
- internal ForContext(ServiceManager serviceManager, Type contractType) {
- this.serviceManager = serviceManager;
- this.contractType = contractType;
- }
-
- /// Uses the specified implementation for the contract
- ///
- /// Implementation that will be used for the contract
- ///
- public void Use(object contractImplementation) { }
-
- ///
- /// Uses the provided object as a prototype for the contract implementation
- ///
- ///
- /// Contract implementation that will be used as a prototype
- ///
- public void UsePrototype(object contractImplementationPrototype) { }
-
- /// Selects the default implementation to use for the contract
- ///
- /// Implementation that will be used as the default for the contract
- ///
- public void UseDefault(Type implementationType) { }
-
- /// Service manager the "For" context operates on
- protected ServiceManager serviceManager;
- /// Contract that is being modified
- protected Type contractType;
-
- }
-
- #endregion // class ForContext
-
- #region class ForContext<>
-
- /// Manages the context of the "For" modifier
- public class ForContext : ForContext {
-
- /// Initializes a new "For" context of the service manager
- /// Service manager the context operates on
- internal ForContext(ServiceManager serviceManager) :
- base(serviceManager, typeof(ContractType)) { }
-
- /// Uses the specified implementation for the contract
- ///
- /// Implementation that will be used for the contract
- ///
- public void Use(ContractType implementation) { }
-
- ///
- /// Uses the provided object as a prototype for the contract implementation
- ///
- ///
- /// Type of the implementation that will be used as a prototype
- ///
- ///
- /// Contract implementation that will be used as a prototype
- ///
- public void UsePrototype(PrototypeType contractImplementationPrototype)
- where PrototypeType : ContractType, ICloneable { }
-
- /// Selects the default implementation to use for the contract
- ///
- /// Implementation that will be used as the default for the contract
- ///
- public void UseDefault()
- where ImplementationType : ContractType { }
-
- }
-
- #endregion // class ForContext<>
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
diff --git a/Source/Services/ServiceManager.Test.cs b/Source/Services/ServiceManager.Test.cs
deleted file mode 100644
index 6146a7b..0000000
--- a/Source/Services/ServiceManager.Test.cs
+++ /dev/null
@@ -1,199 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-#if UNITTEST
-
-using System;
-using System.IO;
-
-using Nuclex.Support.Plugins;
-
-using NUnit.Framework;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- /// Unit Test for the service manager class
- [TestFixture]
- public class ServiceManagerTest {
-
- #region interface IHelloContract
-
- /// A simple contract interface used for testing
- public interface IHelloContract { }
-
- #endregion // interface IHelloContract
-
- #region interface IWorldContract
-
- /// Another simple contract interface used for testing
- public interface IWorldContract { }
-
- #endregion // interface IWorldContract
-
- #region interface IHaveNoImplementation
-
- /// A contract interface that is not implementated anywhere
- public interface IHaveNoImplementation { }
-
- #endregion // interface IHaveNoImplementation
-
- #region class HelloComponent
-
- /// Test component that implements the hello contract
- public class HelloComponent : IHelloContract { }
-
- #endregion // class HelloComponent
-
- #region class WorldComponent
-
- ///
- /// Test component that implements the world contract and requires
- /// an implementation of the hello contract
- ///
- public class WorldComponent : IWorldContract, IHelloContract {
- /// Initializes a new world component
- ///
- /// Array of hello contract implementations that will be used
- ///
- public WorldComponent(IHelloContract[] helloContracts) { }
- }
-
- #endregion // class WorldComponent
-
- #region class IncompleteComponent
-
- ///
- /// Test component that requires an implementation of a contract that has
- /// no implementation available
- ///
- public class IncompleteComponent : IWorldContract {
- /// Initializes the component
- ///
- /// Implementation of the unimplemented interface (:P) to use
- ///
- public IncompleteComponent(IHaveNoImplementation noImplementation) { }
- }
-
- #endregion // class IncompleteComponent
-
- #region class NeedHello
-
- /// Component that needs an implementation of the hello contract
- public class NeedHello : IWorldContract {
- /// Initializes the component
- ///
- /// Implementation of the hello contract that will be used
- ///
- public NeedHello(IHelloContract helloContract) { }
- }
-
- #endregion // class NeedHello
-
- #region class NeedWorld
-
- /// Component that needs an implementation of the world contract
- public class NeedWorld : IHelloContract {
- /// Initializes the component
- ///
- /// Implementation of the world contract that will be used
- ///
- public NeedWorld(IWorldContract worldContract) { }
- }
-
- #endregion // class NeedWorld
-
- ///
- /// Tests whether the GetComponents() method behaves correctly if it is used
- /// without any assemblies loaded
- ///
- [Test]
- public void TestGetComponentsWithoutAssembly() {
- ServiceManager serviceManager = new ServiceManager(new PredefinedTypeLister());
- Assert.That(serviceManager.GetComponents(), Is.Empty);
- }
-
- ///
- /// Tests whether the GetComponents() method can locate a simple component
- ///
- [Test]
- public void TestGetComponents() {
- RepositoryTypeLister typeLister = new RepositoryTypeLister();
- ServiceManager serviceManager = new ServiceManager(typeLister);
- typeLister.Repository.AddAssembly(typeof(ServiceManagerTest).Assembly);
-
- Assert.That(
- serviceManager.GetComponents(),
- Has.Member(typeof(HelloComponent)).And.Member(typeof(WorldComponent))
- );
- }
-
- ///
- /// Tests whether the GetComponents() method correctly determines which
- /// components can have their dependencies completely provided.
- ///
- [Test]
- public void TestFilteredGetComponents() {
- RepositoryTypeLister typeLister = new RepositoryTypeLister();
- ServiceManager serviceManager = new ServiceManager(typeLister);
- typeLister.Repository.AddAssembly(typeof(ServiceManagerTest).Assembly);
-
- Assert.That(
- serviceManager.GetComponents(false),
- Has.Member(typeof(WorldComponent)).And.Member(typeof(IncompleteComponent))
- );
- Assert.That(
- serviceManager.GetComponents(true),
- Has.Member(typeof(WorldComponent)).And.No.Member(typeof(IncompleteComponent))
- );
- }
-
- ///
- /// Tests whether the GetComponents() method can cope with two components
- /// that have a circular dependency through their services.
- ///
- [Test]
- public void TestCircularDependency() {
-
- }
-
- ///
- /// Verifies that the right exception is thrown if the non-generic GetService()
- /// is used on a value type
- ///
- [Test]
- public void TestGetComponentOnValueType() {
- RepositoryTypeLister typeLister = new RepositoryTypeLister();
- ServiceManager serviceManager = new ServiceManager(typeLister);
- typeLister.Repository.AddAssembly(typeof(int).Assembly);
-
- Assert.Throws(
- delegate() { serviceManager.GetService(typeof(int)); }
- );
- }
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER
-
-#endif // UNITTEST
diff --git a/Source/Services/ServiceManager.cs b/Source/Services/ServiceManager.cs
deleted file mode 100644
index 252e64f..0000000
--- a/Source/Services/ServiceManager.cs
+++ /dev/null
@@ -1,326 +0,0 @@
-#region CPL License
-/*
-Nuclex Framework
-Copyright (C) 2002-2010 Nuclex Development Labs
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the IBM Common Public License as
-published by the IBM Corporation; either version 1.0 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-IBM Common Public License for more details.
-
-You should have received a copy of the IBM Common Public
-License along with this library
-*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Reflection;
-using System.Threading;
-
-using Nuclex.Support.Plugins;
-
-#if ENABLE_SERVICEMANAGER
-
-namespace Nuclex.Support.Services {
-
- // Allow Dependency on Container
- // public Foo(IServiceProvider serviceProvider)
- // public Foo(IserviceLocator serviceLocator)
- // public Foo(Container container)
-
- ///
- /// Inversion of Control container that manages the services of an application
- ///
- ///
- ///
- /// This is a very lightweight and simple inversion of control container that
- /// relieves components of their duty to track down implementations for the services
- /// they require to function. It will help with lazy initialization and prevent
- /// components from becoming cross-linked balls of spaghetti references.
- ///
- ///
- /// Here's a short list of the terms used throughout this container and their
- /// specific meaning in this context.
- ///
- ///
- ///
- /// -
- /// Service
- ///
- /// Defined by an interface (service contract) and provided by a component
- /// that implements the service contract. A service provides some kind of
- /// utility to the application, for example it could provide access to
- /// a data base or allow other components to control certain aspects of
- /// the application.
- ///
- ///
- /// -
- /// Contract
- ///
- /// Interface defining the behavior that a service implementation has to
- /// follow. In order for a component to become a suitable candidate for
- /// providing a specific service, it has to implement the service contract
- /// interface and should rigorously follow its specifications.
- ///
- ///
- /// -
- /// Component
- ///
- /// A component is simply a class that implements one or more service
- /// contracts. The service manager will created instances of these classes
- /// when all their dependencies can be provided for and an implementation
- /// of their service contract is requested.
- ///
- ///
- ///
- ///
- ///
- public partial class ServiceManager : IServiceProvider {
-
-#region class Contract
-
- /// Stores the settings for an individual contract
- private class Contract {
-
- ///
- /// Factory by which instances of the contract implementation can be created
- ///
- public IAbstractFactory Factory;
-
- /// How instances of the implementation are to be managed
- public Instancing Instancing;
-
- /// Single global instance of the contract implementation
- ///
- /// Used only if is set to Singleton
- ///
- public object SingletonInstance;
-
- /// Thread-local instance of the contract implementation
- ///
- /// Used only if is set to InstancePerThread
- ///
- public object ThreadLocalInstance {
- get {
- initializeThreadLocalData();
- return Thread.GetData(this.threadLocalDataSlot);
- }
- set {
- initializeThreadLocalData();
- Thread.SetData(this.threadLocalDataSlot, value);
- }
- }
-
- /// Initializes the thread-local data slot
- private void initializeThreadLocalData() {
- if(this.threadLocalDataSlot == null) {
- lock(this) {
- if(this.threadLocalDataSlot == null) {
- this.threadLocalDataSlot = Thread.AllocateDataSlot();
- }
- }
- }
- }
-
- /// Arguments to be passed to the component constructor
- private Dictionary arguments;
-
- /// Data slot for thread local storage
- ///
- /// We're using an explicit data slot because the ThreadStaticAttribute class
- /// can only be used on static fields and also because this class is not
- /// supported by the .NET Compact Framework.
- ///
- private volatile LocalDataStoreSlot threadLocalDataSlot;
-
- }
-
- #endregion // class Contract
-
-#if WINDOWS
-
- /// Initializes a new service manager
- ///
- /// This overload will automatically use a type lister that causes all types
- /// in all loaded assemblies of the calling app domain to be considered
- /// by the service manager for obtaining contract implementations.
- ///
- public ServiceManager() : this(new AppDomainTypeLister()) { }
-
-#endif // WINDOWS
-
- /// Initializes a new service manager
- ///
- /// Type lister providing the types considered by the service manager for
- /// obtaining contract implementations.
- ///
- public ServiceManager(ITypeLister typeLister) {
- this.typeLister = typeLister;
- this.contracts = new Dictionary();
- }
-
- ///
- /// Returns all available implementations for the specified contract
- ///
- ///
- /// A new enumerator for the available contract implementations
- ///
- public IEnumerable GetComponents() where ContractType : class {
- Type contractType = typeof(ContractType);
-
- foreach(Type checkedType in this.typeLister.GetTypes()) {
- bool isImplementationOfContract =
- (!checkedType.IsAbstract) &&
- contractType.IsAssignableFrom(checkedType);
-
- if(isImplementationOfContract) {
- yield return checkedType;
- }
- }
- }
-
- ///
- /// Returns all available implementations for the specified contract
- ///
- ///
- /// If true, only services whose dependencies can be completely
- /// satisfied by the container are returned.
- ///
- ///
- /// A new enumerator for the available contract implementations
- ///
- public IEnumerable GetComponents(bool completeOnly)
- where ContractType : class {
- if(completeOnly) {
- return filterCompleteComponents(GetComponents());
- } else {
- return GetComponents();
- }
- }
-
- ///
- /// Filters a list of components so only components whose dependencies can be
- /// completely provided are enumerated
- ///
- /// Enumerable type list that will be filtered
- ///
- /// Only those components whose dependencies can be completely provided
- ///
- private IEnumerable filterCompleteComponents(IEnumerable types) {
- foreach(Type type in types) {
-
- bool isCandidate =
- (!type.IsValueType) &&
- (!type.IsAbstract) &&
- (type.IsPublic || type.IsNestedPublic);
-
- if(isCandidate) {
-
- ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public);
-
-
-
- // If a contract has been
- Contract contract;
- if(this.contracts.TryGetValue(type, out contract)) {
- yield return type;
- } else {
- }
-
- yield return type;
-
- }
-
- }
- }
-
- ///
- /// Allows the adjustment of the container's behavior in regard to
- /// the specified contract
- ///
- ///
- /// Contract for which the behavior will be adjusted
- ///
- ///
- /// A context object through which the behavior of the container can be
- /// adjusted for the specified type
- ///
- public ForContext For() where ContractType : class {
- return new ForContext(this);
- }
-
- ///
- /// Allows the adjustment of the container's behavior in regard to
- /// the specified contract
- ///
- ///
- /// Contract for which the behavior will be adjusted
- ///
- ///
- /// A context object through which the behavior of the container can be
- /// adjusted for the specified type
- ///
- public ForContext For(Type contractType) {
- return new ForContext(this, contractType);
- }
-
- /// Retrieves the service of the specified type
- ///
- /// Contract for which the service will be retrieved
- ///
- /// The service for the specified contract
- public ContractType GetService() where ContractType : class {
- return (ContractType)GetService(typeof(ContractType));
- }
-
- /// Retrieves the service of the specified type
- ///
- /// Contract for which the service will be retrieved
- ///
- /// The service for the specified contract
- public object GetService(Type contractType) {
- Contract c = resolveContract(contractType);
- return c.Factory.CreateInstance(); // TODO: Honor the contract settings
- }
-
- ///
- /// Resolves all dependencies required to create a service for a contract
- ///
- ///
- /// Type of contract for which to resolve the implementation
- ///
- /// The settings for the contract including a valid factory
- private Contract resolveContract(Type contractType) {
- if(contractType.IsValueType) {
- throw new ArgumentException(
- "Contracts have to be interfaces or classes", "contractType"
- );
- }
- /*
- Contract contract;
- if(this.contracts.TryGetValue(contractType, out contract)) {
- return contract;
- }
- */
-
-
- throw new NotImplementedException();
- }
-
- /// Lists all types partaking in the dependency injection
- private ITypeLister typeLister;
- /// Dictionary with settings for each individual contract
- private Dictionary contracts;
-
- }
-
-} // namespace Nuclex.Support.Services
-
-#endif // ENABLE_SERVICEMANAGER