コード例 #1
0
 private static void RegisterDummies(ITargetContainer targets)
 {
     targets.RegisterType <DummyOne, IDummyOne>();
     targets.RegisterType <DummyTwo, IDummyTwo>();
     targets.RegisterType <DummyThree, IDummyThree>();
     targets.RegisterType <DummyFour, IDummyFour>();
     targets.RegisterType <DummyFive, IDummyFive>();
     targets.RegisterType <DummySix, IDummySix>();
     targets.RegisterType <DummySeven, IDummySeven>();
     targets.RegisterType <DummyEight, IDummyEight>();
     targets.RegisterType <DummyNine, IDummyNine>();
     targets.RegisterType <DummyTen, IDummyTen>();
 }
コード例 #2
0
        public void ShouldGetEnumerableTargetWithThreeRegistrations()
        {
            ITargetContainer targets = CreateTargets();

            // yes - this does register three separate instances of the same type
            targets.RegisterType <NoCtor>();
            targets.RegisterType <NoCtor>();
            targets.RegisterType <NoCtor>();

            var result = Assert.IsType <EnumerableTarget>(targets.Fetch(typeof(IEnumerable <NoCtor>)));

            Assert.False(result.UseFallback);
            Assert.Equal(3, result.Targets.Count());
        }
コード例 #3
0
 private static void RegisterMultiple(ITargetContainer targets)
 {
     targets.RegisterMultiple(
         new[]
     {
         Target.ForType <SimpleAdapterOne>(),
         Target.ForType <SimpleAdapterTwo>(),
         Target.ForType <SimpleAdapterThree>(),
         Target.ForType <SimpleAdapterFour>(),
         Target.ForType <SimpleAdapterFive>()
     },
         typeof(ISimpleAdapter));
     targets.RegisterType <ImportMultiple1>();
     targets.RegisterType <ImportMultiple2>();
     targets.RegisterType <ImportMultiple3>();
 }
        /// <summary>
        /// Same as the <see cref="RegisterType{TObject}(ITargetContainer, Action{IMemberBindingBehaviourBuilder{TObject}})"/> method, except this
        /// creates a registration for <typeparamref name="TService"/> that will be implemented by instances of the type <typeparamref name="TObject"/>,
        /// created via constructor injection.
        /// </summary>
        /// <typeparam name="TObject"></typeparam>
        /// <typeparam name="TService"></typeparam>
        /// <param name="targets">The target container on which the registration is to be performed.</param>
        /// <param name="configureMemberBinding">A callback that will be invoked with a new <see cref="IMemberBindingBehaviourBuilder{TInstance}"/>
        /// object that you can use to configure a custom member binding behaviour for the type <typeparamref name="TObject"/>.  The
        /// <see cref="IMemberBindingBehaviourBuilder{TInstance}.BuildBehaviour"/> method will be called after executing your callback to
        /// obtain the final <see cref="IMemberBindingBehaviour"/>.</param>
        public static void RegisterType <TObject, TService>(this ITargetContainer targets, Action <IMemberBindingBehaviourBuilder <TObject> > configureMemberBinding)
            where TObject : TService
        {
            var factory = MemberBindingBehaviour.For <TObject>();

            configureMemberBinding?.Invoke(factory);
            targets.RegisterType <TObject, TService>(factory.BuildBehaviour());
        }
コード例 #5
0
        public void ShouldGetEnumerableTargetWithOneRegistration()
        {
            ITargetContainer targets = CreateTargets();

            targets.RegisterType <NoCtor>();

            var result = Assert.IsType <EnumerableTarget>(targets.Fetch(typeof(IEnumerable <NoCtor>)));

            Assert.False(result.UseFallback);
            Assert.Single(result.Targets);
        }
コード例 #6
0
 private static void RegisterComplexObject(ITargetContainer targets)
 {
     targets.RegisterSingleton <FirstService, IFirstService>();
     targets.RegisterSingleton <SecondService, ISecondService>();
     targets.RegisterSingleton <ThirdService, IThirdService>();
     targets.RegisterType <SubObjectOne, ISubObjectOne>();
     targets.RegisterType <SubObjectTwo, ISubObjectTwo>();
     targets.RegisterType <SubObjectThree, ISubObjectThree>();
     targets.RegisterType <Complex1, IComplex1>();
     targets.RegisterType <Complex2, IComplex2>();
     targets.RegisterType <Complex3, IComplex3>();
 }
コード例 #7
0
 private static void RegisterStandard(ITargetContainer targets)
 {
     // two options for singletons in Rezolver - a singleton target wrapping
     // another, and a straight constant object.  I think for the purposes of the
     // test we should be wrapping a constructor target.
     targets.RegisterSingleton <Singleton1, ISingleton1>();
     targets.RegisterSingleton <Singleton2, ISingleton2>();
     targets.RegisterSingleton <Singleton3, ISingleton3>();
     targets.RegisterType <Transient1, ITransient1>();
     targets.RegisterType <Transient2, ITransient2>();
     targets.RegisterType <Transient3, ITransient3>();
     targets.RegisterType <Combined1, ICombined1>();
     targets.RegisterType <Combined2, ICombined2>();
     targets.RegisterType <Combined3, ICombined3>();
 }
コード例 #8
0
        private static void RegisterPropertyInjection(ITargetContainer targets)
        {
            // this method is temporary till I add auto property injection - thinking I might do it as
            // an extension target that can be added to any other target (except another target)
            targets.RegisterSingleton <ServiceA, IServiceA>();
            targets.RegisterSingleton <ServiceB, IServiceB>();
            targets.RegisterSingleton <ServiceC, IServiceC>();

            targets.RegisterType <SubObjectA, ISubObjectA>(MemberBindingBehaviour.BindProperties);
            targets.RegisterType <SubObjectB, ISubObjectB>(MemberBindingBehaviour.BindProperties);
            targets.RegisterType <SubObjectC, ISubObjectC>(MemberBindingBehaviour.BindProperties);

            targets.RegisterType <ComplexPropertyObject1, IComplexPropertyObject1>(MemberBindingBehaviour.BindProperties);
            targets.RegisterType <ComplexPropertyObject2, IComplexPropertyObject2>(MemberBindingBehaviour.BindProperties);
            targets.RegisterType <ComplexPropertyObject3, IComplexPropertyObject3>(MemberBindingBehaviour.BindProperties);
        }
コード例 #9
0
 private void RegisterBaseClassListAndCollTestTargets(ITargetContainer targets)
 {
     targets.RegisterType <BaseClass>();
     targets.RegisterType <BaseClassChild, BaseClass>();
     targets.RegisterType <BaseClassGrandchild, BaseClass>();
 }
コード例 #10
0
 private static void RegisterOpenGeneric(ITargetContainer targets)
 {
     targets.RegisterType(typeof(GenericExport <>), typeof(IGenericInterface <>));
     targets.RegisterType(typeof(ImportGeneric <>), typeof(ImportGeneric <>));
 }