using System;
using System.Collections.Generic;
using System.Reflection;
using Nuclex.Support.Plugins;
namespace Nuclex.Support.Services {
#if false
///
/// 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 {
/// Initializes a new service manager
public ServiceManager() {
this.pluginRepository = new PluginRepository();
}
///
/// 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
///
IEnumerable GetImplementations(bool completeOnly)
where ContractType : class {
Type contractType = typeof(ContractType);
Assembly[] loadedAssemblies = this.pluginRepository.LoadedAssemblies.ToArray();
for(int index = 0; index < loadedAssemblies.Length; ++index) {
Type[] assemblyTypes = loadedAssemblies[index].GetTypes();
for(int typeIndex = 0; typeIndex < assemblyTypes.Length; ++typeIndex) {
Type checkedType = assemblyTypes[typeIndex];
if(contractType.IsAssignableFrom(checkedType)) {
}
}
}
yield return null;
}
private struct CachedContractLookUp {
public Type[] ValidComponents;
public int Version;
}
private Dictionary cachedContracts;
private int version;
///
/// 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);
}
// Allow Dependency on Container
// public Foo(IServiceProvider serviceProvider)
// public Foo(IserviceLocator serviceLocator)
// public Foo(Container container)
public ContractType GetService() where ContractType : class {
throw new NotImplementedException();
}
/// Retrieves the service of the specified type
///
/// Contract for which the service will be retrieved
///
/// The service for the specified contract
object IServiceProvider.GetService(Type contractType) {
throw new NotImplementedException();
}
///
/// Contains all assemblies partaking in the dependency injection scheme
///
private PluginRepository pluginRepository;
}
#endif
} // namespace Nuclex.Support.DependencyInjection