Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ sdk/test/Performance/**/BenchmarkDotNet.Artifacts/*
#protocol-tests
sdk/test/ProtocolTests/Generated/**/model
sdk/test/ProtocolTests/Generated/**/sources
sdk/test/ProtocolTests/Generated/**/build-info
sdk/test/ProtocolTests/Generated/**/build-info

# macOS
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Amazon.Runtime.Credentials.Internal;
using Microsoft.Extensions.Logging;

namespace AWSSDK.Extensions.NETCore.Setup
namespace AWSSDK.Extensions.NETCore.Setup.Impl
{
/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using Amazon.Runtime;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
///
/// </summary>
public static class AWSCredentialsServiceCollectionExtensions
{
/// <summary>
///
/// </summary>
/// <param name="collection"></param>
/// <param name="lifetime"></param>
/// <returns></returns>
public static IServiceCollection AddAWSCredentials(
this IServiceCollection collection,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
{
collection.Add(new ServiceDescriptor(typeof(AWSCredentials), sp => sp.CreateDefaultAWSCredentials(), lifetime));
return collection;
}

/// <summary>
///
/// </summary>
/// <param name="collection"></param>
/// <param name="credentials"></param>
/// <returns></returns>
public static IServiceCollection AddAWSCredentials(
this IServiceCollection collection,
AWSCredentials credentials)
{
collection.Add(new ServiceDescriptor(typeof(AWSCredentials), credentials));
return collection;
}

/// <summary>
///
/// </summary>
/// <param name="collection"></param>
/// <param name="credentialsFunc"></param>
/// <param name="lifetime"></param>
/// <returns></returns>
public static IServiceCollection AddAWSCredentials(
this IServiceCollection collection,
Func<IServiceProvider, AWSCredentials> credentialsFunc,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
{
collection.Add(new ServiceDescriptor(typeof(AWSCredentials), credentialsFunc, lifetime));
return collection;
}

/// <summary>
///
/// </summary>
/// <param name="collection"></param>
/// <param name="lifetime"></param>
/// <returns></returns>
public static IServiceCollection TryAddAWSCredentials(
this IServiceCollection collection,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
{
collection.TryAdd(new ServiceDescriptor(typeof(AWSCredentials), sp => sp.CreateDefaultAWSCredentials(), lifetime));
return collection;
}

/// <summary>
///
/// </summary>
/// <param name="collection"></param>
/// <param name="credentials"></param>
/// <returns></returns>
public static IServiceCollection TryAddAWSCredentials(
this IServiceCollection collection,
AWSCredentials credentials)
{
collection.TryAdd(new ServiceDescriptor(typeof(AWSCredentials), credentials));
return collection;
}

/// <summary>
///
/// </summary>
/// <param name="collection"></param>
/// <param name="credentialsFunc"></param>
/// <param name="lifetime"></param>
/// <returns></returns>
public static IServiceCollection TryAddAWSCredentials(
this IServiceCollection collection,
Func<IServiceProvider, AWSCredentials> credentialsFunc,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
{
collection.TryAdd(new ServiceDescriptor(typeof(AWSCredentials), credentialsFunc, lifetime));
return collection;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Amazon.Extensions.NETCore.Setup;
using Amazon.Runtime;
using AWSSDK.Extensions.NETCore.Setup;
using AWSSDK.Extensions.NETCore.Setup.Impl;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
///
/// </summary>
public static class AWSCredentialsServiceProviderExtensions
{
/// <summary>
///
/// </summary>
/// <param name="sp"></param>
/// <param name="options"></param>
/// <returns></returns>
public static AWSCredentials CreateDefaultAWSCredentials(this IServiceProvider sp, AWSOptions options = null)
{
options = options ?? sp.GetService<AWSOptions>() ?? new AWSOptions();
return new DefaultAWSCredentials(options, sp.GetService<ILogger>());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using Amazon.Extensions.NETCore.Setup;
using Amazon.Runtime;
using AWSSDK.Extensions.NETCore.Setup.Impl;

namespace AWSSDK.Extensions.NETCore.Setup
{
Expand All @@ -15,13 +17,15 @@ public static class AWSOptionsExtensions
/// </summary>
/// <typeparam name="T">The service interface that a service client will be created for.</typeparam>
/// <returns>The service client that implements the service interface.</returns>
public static T CreateServiceClient<T>(this AWSOptions options)
[Obsolete("Prefer creating a service client via one of the IServiceCollection or IServiceProvider extensions.")]
public static T CreateServiceClient<T>(this AWSOptions options, AWSCredentials credentials = null, IClientConfigFactory clientConfigFactory = null)
where T : class, IAmazonService
{
var credentials = new DefaultAWSCredentials(options, null);
var clientFactory = new ClientFactory<T>(options, credentials, null);
credentials = credentials ?? new DefaultAWSCredentials(options, null);
clientConfigFactory = clientConfigFactory ?? new DefaultClientConfigFactory();
var clientFactory = new DefaultClientFactory(options, credentials, null, clientConfigFactory);

return clientFactory.CreateServiceClient() as T;
return clientFactory.CreateServiceClient<T>() as T;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using System;
using Amazon.Extensions.NETCore.Setup;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// This class adds extension methods to IServiceCollection making it easier to add Amazon service clients
/// to the NET Core dependency injection framework.
/// </summary>
public static class AWSOptionsServiceCollectionExtensions
{
/// <summary>
/// Adds the AWSOptions object to the dependency injection framework providing information
/// that will be used to construct Amazon service clients.
/// </summary>
/// <param name="collection"></param>
/// <param name="options">The default AWS options used to construct AWS service clients with.</param>
/// <returns>Returns back the IServiceCollection to continue the fluent system of IServiceCollection.</returns>
public static IServiceCollection AddDefaultAWSOptions(this IServiceCollection collection, AWSOptions options)
{
collection.Add(new ServiceDescriptor(typeof(AWSOptions), options));
return collection;
}

/// <summary>
/// Adds the AWSOptions object to the dependency injection framework providing information
/// that will be used to construct Amazon service clients.
/// </summary>
/// <param name="collection"></param>
/// <param name="implementationFactory">The factory that creates the default AWS options.
/// The AWS options will be used to construct AWS service clients
/// </param>
/// <param name="lifetime">The lifetime of the AWSOptions. The default is Singleton.</param>
/// <returns>Returns back the IServiceCollection to continue the fluent system of IServiceCollection.</returns>
public static IServiceCollection AddDefaultAWSOptions(
this IServiceCollection collection,
Func<IServiceProvider, AWSOptions> implementationFactory,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
{
collection.Add(new ServiceDescriptor(typeof(AWSOptions), implementationFactory, lifetime));
return collection;
}

/// <summary>
/// Adds the AWSOptions object to the dependency injection framework providing information
/// that will be used to construct Amazon service clients if they haven't already been registered.
/// </summary>
/// <param name="collection"></param>
/// <param name="options">The default AWS options used to construct AWS service clients with.</param>
/// <returns>Returns back the IServiceCollection to continue the fluent system of IServiceCollection.</returns>
public static IServiceCollection TryAddDefaultAWSOptions(this IServiceCollection collection, AWSOptions options)
{
collection.TryAdd(new ServiceDescriptor(typeof(AWSOptions), options));
return collection;
}

/// <summary>
/// Adds the AWSOptions object to the dependency injection framework providing information
/// that will be used to construct Amazon service clients if they haven't already been registered.
/// </summary>
/// <param name="collection"></param>
/// <param name="implementationFactory">The factory that creates the default AWS options.
/// The AWS options will be used to construct AWS service clients
/// </param>
/// <param name="lifetime">The lifetime of the AWSOptions. The default is Singleton.</param>
/// <returns>Returns back the IServiceCollection to continue the fluent system of IServiceCollection.</returns>
public static IServiceCollection TryAddDefaultAWSOptions(
this IServiceCollection collection,
Func<IServiceProvider, AWSOptions> implementationFactory,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
{
collection.TryAdd(new ServiceDescriptor(typeof(AWSOptions), implementationFactory, lifetime));
return collection;
}
}
}
Loading
Loading