using System;
using System.Collections.Generic;
namespace Diametric.Service
{
///
/// An implementation of IServiceProvider that uses a dictionary
///
public class DictionaryServiceProvider:IServiceProvider
{
private Dictionary services = new Dictionary();
public DictionaryServiceProvider()
{
}
#region IServiceProvider Members
///
/// Returns the specified service or null if the service doesn't exist.
///
///
///
public object GetService(Type serviceType)
{
object service = null;
services.TryGetValue( serviceType, out service );
return service;
}
#endregion
#region Public API
///
/// Adds a service to the service provider's list of services using the object's type as the key.
///
///
public void AddService(object service)
{
services.Add( service.GetType(), service );
}
///
/// Adds a service to the service provider's list of services using the provided Type as the key.
///
///
public void AddService(object service, Type key)
{
services.Add( key, service );
}
#endregion
}
}