日期:2014-05-17 浏览次数:21120 次
namespace Skight.LightWeb.Domain { public interface Resolver { Dependency get<Dependency>(); } }
using System; using System.Collections.Generic; namespace Skight.LightWeb.Domain { public class ResolverImpl:Resolver { private readonly IDictionary<Type, object> item_resolvers; public ResolverImpl(IDictionary<Type, object> itemResolvers) { item_resolvers = itemResolvers; } public Dependency get<Dependency>() { return (Dependency) item_resolvers[typeof (Dependency)]; } }
using System; using System.Collections.Generic; using Machine.Specifications; namespace Skight.LightWeb.Domain.Specs { public class ResolverSpecs { private Establish context = () => { var dictioary = new Dictionary<Type, object>(); dictioary.Add(typeof (MockInterface), new MockImplementaion()); subject = new ResolverImpl(dictioary); }; private It Container_get_by_interface_should_return_its_implementation_class = () => subject.get<MockInterface>().ShouldBeOfType<MockImplementaion>(); private static ResolverImpl subject; private interface MockInterface { } private class MockImplementaion : MockInterface { } } }