using System; namespace Tapeti.Default { /** * !! IoC Container 9000 !! * * ...you probably want to replace this one as soon as possible. * * A Simple Injector implementation is provided in the Tapeti.SimpleInjector package. */ public class DefaultDependencyResolver : IDependencyInjector { private readonly Lazy controllerFactory; private readonly Lazy routingKeyStrategy = new Lazy(); private readonly Lazy messageSerializer = new Lazy(); public DefaultDependencyResolver(Func publisherFactory) { controllerFactory = new Lazy(() => new DefaultControllerFactory(publisherFactory)); } public T Resolve() where T : class { if (typeof(T) == typeof(IControllerFactory)) return (T)(controllerFactory.Value as IControllerFactory); if (typeof(T) == typeof(IRoutingKeyStrategy)) return (T)(routingKeyStrategy.Value as IRoutingKeyStrategy); if (typeof(T) == typeof(IMessageSerializer)) return (T)(messageSerializer.Value as IMessageSerializer); return default(T); } public void RegisterController(Type type) { controllerFactory.Value.RegisterController(type); } } }