/// <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); }
/// <summary> /// Configure the <see cref="IApiCommandContentSerializer"/> serializers and <see cref="IApiCommandContentDeserializer"/> deserializers. /// </summary> /// <param name="builder"></param> /// <returns></returns> public static IDependencyBuilder ConfigureApi(this IDependencyBuilder builder) { builder.Bind <DefaultFormUrlEncodedContentParser>().Resolve <IDefaultFormUrlEncodedContentParser>().WithKey(ApiSerializer.FormUrlEncoded); builder.Bind <ApiCommandContentSerializerFormUrlEncoded>().Resolve <IApiCommandContentSerializer>().WithKey(ApiSerializer.FormUrlEncoded); builder.Bind <ApiCommandContentSerializerJson>().Resolve <IApiCommandContentSerializer>().WithKey(ApiSerializer.Json); builder.Bind <ApiCommandContentSerializerString>().Resolve <IApiCommandContentSerializer>().WithKey(ApiSerializer.String); builder.Bind <ApiCommandContentSerializerXml>().Resolve <IApiCommandContentSerializer>().WithKey(ApiSerializer.Xml); builder.Bind <ApiCommandContentSerializerFormUrlEncoded>().Resolve <IApiCommandContentDeserializer>().WithKey(ApiSerializer.FormUrlEncoded); builder.Bind <ApiCommandContentSerializerJson>().Resolve <IApiCommandContentDeserializer>().WithKey(ApiSerializer.Json); builder.Bind <ApiCommandContentSerializerString>().Resolve <IApiCommandContentDeserializer>().WithKey(ApiSerializer.String); builder.Bind <ApiCommandContentSerializerXml>().Resolve <IApiCommandContentDeserializer>().WithKey(ApiSerializer.Xml); return(builder); }
public static void ConfigurePerformanceTest(this IDependencyBuilder builder) { builder.Bind <PerformanceMethodTest>().Resolve <IPerformanceMethodTest>(); builder.BindFunction((ctx) => PerformanceMethodTest.Method()).Resolve <IPerformanceMethodResultTest>(); builder.Bind <PerformanceConstructParamTest>().Resolve <IPerformanceConstructParam1Test>(); builder.Bind <PerformanceConstructParamTest>().Resolve <IPerformanceConstructParam2Test>(); builder.Bind <PerformanceConstructParamTest>().Resolve <IPerformanceConstructParam3Test>(); builder.Bind <PerformanceConstructTest>().Resolve <IPerformanceConstructTest>(); builder.Bind <PerformanceSingletonTest>().Resolve <IPerformanceSingletonTest>().InSingletonScope(); builder.BindInstance(new PerformanceInstanceTest()).Resolve <IPerformanceInstanceTest>(); }
/// <summary> /// Configure the extentions required by the IOC. /// </summary> /// <param name="builder"></param> /// <returns></returns> public static IDependencyBuilder ConfigureExtentions(this IDependencyBuilder builder) { builder.Bind <DependencyResolver>().Resolve <IDependencyResolver>().InSingletonScope(); return(builder); }
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)); }