Пример #1
0
        /// <summary>
        /// Configure the <see cref="IHttpResponseFactory"/> and <see cref="IApiCommandFactory"/> and bind the <see cref="IApiCommandAsync"/> for all commands under <see cref="HttpRequestType"/>
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IDependencyBuilder ConfigureApi(this IDependencyBuilder builder)
        {
            builder.Bind <HttpResponseFactory>().Resolve <IHttpResponseFactory>().InSingletonScope();
            builder.Bind <ApiCommandFactory>().Resolve <IApiCommandFactory>().InSingletonScope();
            builder.Bind(typeof(ApiCommandContentTypeMap <>)).Resolve(typeof(IApiCommandContentTypeMap <>));

            builder.BindFactory <IApiCommandFactory>(nameof(IApiCommandFactory.CreateGetCommand)).Resolve <IApiCommandAsync>().WithKey(HttpRequestType.Get);
            builder.BindFactory <IApiCommandFactory>(nameof(IApiCommandFactory.CreateDeleteCommand)).Resolve <IApiCommandAsync>().WithKey(HttpRequestType.Delete);
            builder.BindFactory <IApiCommandFactory>(nameof(IApiCommandFactory.CreatePutCommand)).Resolve <IApiCommandAsync>().WithKey(HttpRequestType.Put);
            builder.BindFactory <IApiCommandFactory>(nameof(IApiCommandFactory.CreatePostCommand)).Resolve <IApiCommandAsync>().WithKey(HttpRequestType.Post);
            builder.BindFactory <IApiCommandFactory>(nameof(IApiCommandFactory.CreatePatchCommand)).Resolve <IApiCommandAsync>().WithKey(HttpRequestType.Patch);
            builder.BindFactory <IApiCommandFactory>(nameof(IApiCommandFactory.CreateSendCommand)).Resolve <IApiCommandAsync>().WithKey(HttpRequestType.Custom);

            return(builder);
        }
Пример #2
0
 public static void ConfigureTest(this IDependencyBuilder builder)
 {
     builder.Bind <NormalClass>().Resolve <INormalClass>().InTransientScope();
     builder.Bind <CallingClass>().Resolve <ICallingClass>();
     builder.Bind <ChildClass>().Resolve <IChildClass>();
     builder.Bind <SingletonClassTest>().Resolve <ISingletonClass>().InSingletonScope();
     builder.Bind <SingletonClassTest>().Resolve <ISingletonNamedClass>().InSingletonScope().WithKey(nameof(ISingletonNamedClass));
     builder.Bind <SingletonClassTest>().Resolve <ISingletonEnumClass>().InSingletonScope().WithKey(EnumAsKey.Key);
     builder.Bind <SingletonClassTest>().Resolve <ISingletonKeyClass>().InSingletonScope().WithKey(typeof(ISingletonKeyClass));
     builder.Bind <SingletonSameInstanceClassTest>().Resolve(typeof(ISingletonSameInstanceClassTest), typeof(ISingletonSameInstanceClassTest2), typeof(ISingletonSameInstanceClassTest3), typeof(ISingletonSameInstanceClassTest4)).InSingletonScope();
     builder.Bind <MultipleConstructorClass>().Resolve <IMultipleConstructorClass>();
     builder.Bind <FactoryClass>().Resolve <IFactoryClass>().InSingletonScope();
     builder.BindFunction((ctx) => ctx.Ioc.Resolve <IFactoryClass>().ResolveFactoryResolutionClass(ctx.GetArguments())).Resolve <IFactoryResolutionClass>().WithKey(MethodWithArgs);
     builder.BindFunction((ctx) => ctx.Ioc.Resolve <IFactoryClass>().ResolveFactoryResolutionClass()).Resolve <IFactoryResolutionClass>().WithKey(MethodWithNoArgs);
     builder.Bind <FactoryResolutionClass>().Resolve <IFactoryResolutionClass>().WithKey(NotMethod);
     builder.Bind <NotBindedClass>().Resolve <INotBindedKeyed>().WithKey(NotResolvedName);
     builder.Bind <NotBindedClass>().Resolve <INotBindedKeyed>().WithKey(EnumAsKey.Key);
     builder.Bind <NotBindedClass>().Resolve <INotBindedKeyed>().WithKey(typeof(INormalClass));
     builder.Bind(typeof(GenericTypeTest <>)).Resolve(typeof(IGenericTypeTests <>));
     builder.Bind(typeof(GenericTypeTest <>)).Resolve(typeof(IGenericSingletonTests <>)).InSingletonScope();
     builder.Bind <MultipleBindingClassTest1>().Resolve <IMultipleBindingClassTest>().WithKey(nameof(MultipleBindingClassTest1));
     builder.Bind <MultipleBindingClassTest2>().Resolve <IMultipleBindingClassTest>().WithKey(nameof(MultipleBindingClassTest2));
     builder.Bind <MultipleBindingClassTest3>().Resolve <IMultipleBindingClassTest>().WithKey(nameof(MultipleBindingClassTest3));
     builder.Bind <MultipleBindingConstructorClassTest>().Resolve <IMultipleBindingConstructorClassTest>();
     builder.Bind(typeof(MultipleBindingConstructorClassTest <>)).Resolve(typeof(IMultipleBindingConstructorClassTest <>));
     builder.Bind(typeof(MultipleBindingClassTest1 <>)).Resolve(typeof(IMultipleBindingClassTest <>)).WithKey(typeof(MultipleBindingClassTest1 <>).Name);
     builder.Bind(typeof(MultipleBindingClassTest2 <>)).Resolve(typeof(IMultipleBindingClassTest <>)).WithKey(typeof(MultipleBindingClassTest2 <>).Name);
     builder.Bind(typeof(MultipleBindingClassTest3 <>)).Resolve(typeof(IMultipleBindingClassTest <>)).WithKey(typeof(MultipleBindingClassTest3 <>).Name);
     builder.Bind <FactoryMethodClass>().Resolve <IFactoryMethodClass>().InSingletonScope();
     builder.BindFactory <IFactoryMethodClass>(nameof(IFactoryMethodClass.Method)).Resolve <IFactoryMethodResolutionClass>();
     builder.BindFactory <IFactoryMethodClass>(nameof(IFactoryMethodClass.Method)).Resolve <IFactoryMethodResolutionNamedClass>().WithKey(Named1);
     builder.BindFactory <IFactoryMethodClass>(nameof(IFactoryMethodClass.Method)).Resolve <IFactoryMethodResolutionNamedClass>().WithKey(Named2);
     builder.BindFactory <IFactoryMethodClass>(nameof(IFactoryMethodClass.Singleton)).Resolve <IFactoryMethodResolutionSingletonClass>().InSingletonScope();
     builder.Bind(typeof(FactoryMethodClass <>)).Resolve(typeof(IFactoryMethodClass <>)).InSingletonScope();
     builder.BindFactory(typeof(IFactoryMethodClass <>), "Method").Resolve(typeof(IFactoryMethodResolutionClass <>));
     builder.BindFactory(typeof(IFactoryMethodClass <>), "Singleton").Resolve(typeof(IFactoryMethodResolutionSingletonClass <>)).InSingletonScope();
     builder.Bind <ResolveAllTest>().ResolveAll().WithKey(nameof(ResolveAllTest));
     builder.Bind <ResolveAllTest2>().ResolveAll().WithKey(nameof(ResolveAllTest2));
 }