Beispiel #1
0
 public RequiresMyServicesWithDefaults(MyService1 service1,
                                       MyService2 service2 = null,
                                       MyService3 service3 = null)
     : base(service1,
            service2 ?? Default2,
            service3 ?? Default3)
 {
 }
Beispiel #2
0
 public RequiresMyServices(MyService1 service1,
                           MyService2 service2,
                           MyService3 service3)
 {
     Service1 = service1;
     Service2 = service2;
     Service3 = service3;
 }
        public void Should_register_interface_automatically_only_for_one_iface()
        {
            // Setup
            var ms = new MyService2(null);

            _sut.Add(ms);
            try
            {
                _sut.Get <IMyService2>();
                Assert.Fail();
            }
            catch (PlasmaException) {}
        }
        public void ShouldUseArgumentToSupplyDependency()
        {
            var container = new Container();

            // <example6>
            container.RegisterType <RequiresIMyService, IRequiresIMyService>();
            container.RegisterAutoFunc <IMyService, IRequiresIMyService>();

            var factory    = container.Resolve <Func <IMyService, IRequiresIMyService> >();
            var myService2 = new MyService2();

            var instance = factory(myService2);

            // </example6>

            Assert.Same(instance.Service, myService2);
        }
Beispiel #5
0
        public void GetService()
        {
            using (var u = new TestUniverse())
            {
                // Arrange
                u.Registrar.Setup(r => r.LookUp(typeof(IMyService), "KEY"))
                .Returns(typeof(MyService2));
                var svc = new MyService2();
                u.Services.Setup(s => s.GetService(typeof(MyService2))).Returns(svc);

                // Act
                var actualSvc = u.Factory.GetService <IMyService>("KEY");

                // Assert
                Assert.That(actualSvc, Is.SameAs(svc));
            }
        }
        public void Fluent_ShouldBindIdenticalMembersWithDifferentServices()
        {
            // <example8>
            var container = new Container();

            container.RegisterType <MyService1>();
            MyService2 constantService2 = new MyService2();

            container.RegisterType <Has2IdenticalMembers>(b =>
                                                          b.Bind(s => s.Service1).ToType <MyService1>()
                                                          .Bind(s => s.Service2).ToObject(constantService2));

            var result = container.Resolve <Has2IdenticalMembers>();

            Assert.NotNull(result.Service1);
            Assert.Same(constantService2, result.Service2);
            // </example8>
        }
        public void Should_get_or_create_by_provided_factory()
        {
            // Setup
            var now = _sut.TryGet <IMyService2>();

            Assert.IsNull(now);

            var place = new MyService2(null);

            int cnt = 0;

            now = _sut.Get <IMyService2>(() => { cnt++; return(place); });

            Assert.AreEqual(place, now);
            Assert.AreEqual(1, cnt);
            now = _sut.Get <IMyService2>(() => { cnt++; return(place); });
            Assert.AreEqual(1, cnt);
        }
 public MyService1(MyService2 service2)
 {
     _service2 = service2;
 }
 public MyService1Func(Func <MyService2> service2)
 {
     _service2 = service2.Invoke();
 }
 public Requires2MyServices(MyService2 first,
                            MyService3 second)
 {
     First  = first;
     Second = second;
 }