Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename: callerOptions -> callerBuilder #528

Merged
merged 1 commit into from
Mar 29, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class CallerBase
/// </summary>
protected virtual Func<IServiceProvider, IResponseMessage>? ResponseMessageFactory => null;

protected CallerBuilder CallerOptions { get; private set; } = default!;
protected CallerBuilder CallerBuilder { get; private set; } = default!;

public ILogger? Logger { get; private set; }

Expand All @@ -41,9 +41,9 @@ protected virtual ICaller GetCaller()

public abstract void UseCallerExtension();

public void SetCallerOptions(CallerBuilder callerOptionsBuilder, string name)
internal void SetCallerBuilder(CallerBuilder callerBuilder, string name)
{
CallerOptions = callerOptionsBuilder;
CallerBuilder = callerBuilder;
Name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace Masa.BuildingBlocks.Service.Caller;
public static class CallerBuilderExtensions
{
public static void UseCustomCaller(
this CallerBuilder callerOptionsBuilder,
this CallerBuilder callerBuilder,
Func<IServiceProvider, IManualCaller> implementationFactory)
{
callerOptionsBuilder.Services.Configure<CallerFactoryOptions>(callerOptions =>
callerBuilder.Services.Configure<CallerFactoryOptions>(factoryOptions =>
{
if (callerOptions.Options.Any(relation => relation.Name.Equals(callerOptionsBuilder.Name, StringComparison.OrdinalIgnoreCase)))
if (factoryOptions.Options.Any(relation => relation.Name.Equals(callerBuilder.Name, StringComparison.OrdinalIgnoreCase)))
throw new ArgumentException(
$"The caller name already exists, please change the name, the repeat name is [{callerOptionsBuilder.Name}]");
$"The caller name already exists, please change the name, the repeat name is [{callerBuilder.Name}]");

callerOptions.Options.Add(new MasaRelationOptions<IManualCaller>(
callerOptionsBuilder.Name,
factoryOptions.Options.Add(new MasaRelationOptions<IManualCaller>(
callerBuilder.Name,
implementationFactory));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public static void UseAuthentication(

AddAuthenticationCore(masaCallerClientBuilder.Services);

masaCallerClientBuilder.Services.Configure<AuthenticationServiceFactoryOptions>(callerOptions =>
masaCallerClientBuilder.Services.Configure<AuthenticationServiceFactoryOptions>(factoryOptions =>
{
if (callerOptions.Options.Any(relation
if (factoryOptions.Options.Any(relation
=> relation.Name.Equals(masaCallerClientBuilder.Name, StringComparison.OrdinalIgnoreCase)))
throw new ArgumentException(
$"The caller name already exists, please change the name, the repeat name is [{masaCallerClientBuilder.Name}]");

callerOptions.Options.Add(new AuthenticationServiceRelationOptions(masaCallerClientBuilder.Name, implementationFactory));
factoryOptions.Options.Add(new AuthenticationServiceRelationOptions(masaCallerClientBuilder.Name, implementationFactory));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static void AddAutomaticCaller(
var callerBase = (constructorInfo.Invoke(parameters.ToArray()) as CallerBase)!;

var name = callerBase.Name ?? type.FullName ?? type.Name;
callerBase.SetCallerOptions(new CallerBuilder(services, name), name);
callerBase.SetCallerBuilder(new CallerBuilder(services, name), name);
callerBase.Initialize(serviceProvider, type);

return callerBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public static void UseCustomObjectStorage(
Func<IServiceProvider, IManualObjectStorageClient> implementationFactory,
Func<IServiceProvider, IBucketNameProvider> bucketNameImplementationFactory)
{
objectStorageBuilder.Services.Configure<ObjectStorageFactoryOptions>(callerOptions =>
objectStorageBuilder.Services.Configure<ObjectStorageFactoryOptions>(factoryOptions =>
{
if (callerOptions.Options.Any(relation => relation.Name.Equals(objectStorageBuilder.Name, StringComparison.OrdinalIgnoreCase)))
if (factoryOptions.Options.Any(relation => relation.Name.Equals(objectStorageBuilder.Name, StringComparison.OrdinalIgnoreCase)))
throw new ArgumentException(
$"The ObjectStorage name already exists, please change the name, the repeat name is [{objectStorageBuilder.Name}]");

callerOptions.Options.Add(new(objectStorageBuilder.Name, implementationFactory));
factoryOptions.Options.Add(new(objectStorageBuilder.Name, implementationFactory));
});

objectStorageBuilder.Services.Configure<BucketNameFactoryOptions>(callerOptions =>
objectStorageBuilder.Services.Configure<BucketNameFactoryOptions>(factoryOptions =>
{
if (callerOptions.Options.Any(relation => relation.Name.Equals(objectStorageBuilder.Name, StringComparison.OrdinalIgnoreCase)))
if (factoryOptions.Options.Any(relation => relation.Name.Equals(objectStorageBuilder.Name, StringComparison.OrdinalIgnoreCase)))
throw new ArgumentException(
$"The Bucket name already exists, please change the name, the repeat name is [{objectStorageBuilder.Name}]");

callerOptions.Options.Add(new(objectStorageBuilder.Name, bucketNameImplementationFactory));
factoryOptions.Options.Add(new(objectStorageBuilder.Name, bucketNameImplementationFactory));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public static class MasaConfigurationExtensions
public static IMasaConfigurationBuilder UseDcc(
this IMasaConfigurationBuilder builder,
Action<JsonSerializerOptions>? jsonSerializerOptions = null,
Action<CallerBuilder>? callerOptions = null,
Action<CallerBuilder>? callerBuilder = null,
string sectionName = "DccOptions")
{
var configurationSection = builder.Configuration.GetSection(sectionName);
var dccOptions = configurationSection.Get<DccOptions>();
return builder.UseDcc(dccOptions, jsonSerializerOptions, callerOptions);
return builder.UseDcc(dccOptions, jsonSerializerOptions, callerBuilder);
}

public static IMasaConfigurationBuilder UseDcc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MasaDaprClientBuilder UseDapr()
{
UseDaprPre();

var daprClientBuilder = CallerOptions.UseDapr(callerClient =>
var daprClientBuilder = CallerBuilder.UseDapr(callerClient =>
{
callerClient.AppId = AppId;
ConfigMasaCallerClient(callerClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@

namespace Masa.BuildingBlocks.Service.Caller;

public static class CallerOptionsExtensions
public static class CallerBuilderExtensions
{
public static MasaDaprClientBuilder UseDapr(this CallerBuilder callerOptionsBuilder,
public static MasaDaprClientBuilder UseDapr(this CallerBuilder callerBuilder,
Action<MasaDaprClient> masDaprClientConfigure,
Action<DaprClientBuilder>? configure = null)
{
MasaArgumentException.ThrowIfNull(masDaprClientConfigure);

callerOptionsBuilder.Services.AddDaprClient(configure);
callerBuilder.Services.AddDaprClient(configure);

return callerOptionsBuilder.UseDaprCore(() =>
return callerBuilder.UseDaprCore(() =>
{
callerOptionsBuilder.UseCustomCaller(serviceProvider =>
callerBuilder.UseCustomCaller(serviceProvider =>
{
var masaDaprClient = new MasaDaprClient(serviceProvider);
masDaprClientConfigure.Invoke(masaDaprClient);
var appid = serviceProvider.GetRequiredService<ICallerProvider>().CompletionAppId(masaDaprClient.AppId);

return new DaprCaller(
serviceProvider,
callerOptionsBuilder.Name,
callerBuilder.Name,
appid,
masaDaprClient.RequestMessageFactory,
masaDaprClient.ResponseMessageFactory);
});
});
}

private static MasaDaprClientBuilder UseDaprCore(this CallerBuilder callerOptionsBuilder,
private static MasaDaprClientBuilder UseDaprCore(this CallerBuilder callerBuilder,
Action action)
{
callerOptionsBuilder.Services.TryAddSingleton<ICallerProvider, DefaultCallerProvider>();
callerOptionsBuilder.Services.AddOptions();
callerBuilder.Services.TryAddSingleton<ICallerProvider, DefaultCallerProvider>();
callerBuilder.Services.AddOptions();
action.Invoke();
return new MasaDaprClientBuilder(callerOptionsBuilder.Services, callerOptionsBuilder.Name);
return new MasaDaprClientBuilder(callerBuilder.Services, callerBuilder.Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@

namespace Masa.BuildingBlocks.Service.Caller;

public static class CallerOptionsExtensions
public static class CallerBuilderExtensions
{
public static MasaHttpClientBuilder UseHttpClient(this CallerBuilder callerOptionsBuilder)
=> callerOptionsBuilder.UseHttpClientCore(null);
public static MasaHttpClientBuilder UseHttpClient(this CallerBuilder callerBuilder)
=> callerBuilder.UseHttpClientCore(null);

public static MasaHttpClientBuilder UseHttpClient(this CallerBuilder callerOptionsBuilder,
public static MasaHttpClientBuilder UseHttpClient(this CallerBuilder callerBuilder,
Action<MasaHttpClient> clientConfigure)
{
MasaArgumentException.ThrowIfNull(clientConfigure);

return callerOptionsBuilder.UseHttpClientCore(clientConfigure);
return callerBuilder.UseHttpClientCore(clientConfigure);
}

private static MasaHttpClientBuilder UseHttpClientCore(this CallerBuilder callerOptionsBuilder,
private static MasaHttpClientBuilder UseHttpClientCore(this CallerBuilder callerBuilder,
Action<MasaHttpClient>? clientConfigure)
{
callerOptionsBuilder.Services.AddHttpClient(callerOptionsBuilder.Name);
callerBuilder.Services.AddHttpClient(callerBuilder.Name);

callerOptionsBuilder.UseCustomCaller(serviceProvider =>
callerBuilder.UseCustomCaller(serviceProvider =>
{
var masaHttpClient = new MasaHttpClient(serviceProvider);
clientConfigure?.Invoke(masaHttpClient);
var httpClient = serviceProvider.GetRequiredService<IHttpClientFactory>().CreateClient(callerOptionsBuilder.Name);
var httpClient = serviceProvider.GetRequiredService<IHttpClientFactory>().CreateClient(callerBuilder.Name);
masaHttpClient.ConfigureHttpClient(httpClient);
return new HttpClientCaller(
httpClient,
serviceProvider,
callerOptionsBuilder.Name,
callerBuilder.Name,
masaHttpClient.Prefix,
masaHttpClient.RequestMessageFactory,
masaHttpClient.ResponseMessageFactory);
});
return new MasaHttpClientBuilder(callerOptionsBuilder.Services, callerOptionsBuilder.Name);
return new MasaHttpClientBuilder(callerBuilder.Services, callerBuilder.Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private MasaHttpClientBuilder UseHttpClient()
{
UseHttpClientPre();

var masaHttpClientBuilder = CallerOptions.UseHttpClient(callerClient =>
var masaHttpClientBuilder = CallerBuilder.UseHttpClient(callerClient =>
{
callerClient.Prefix = Prefix;
callerClient.BaseAddress = BaseAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class CallerTest
public void TestAppIdByUseDapr()
{
var services = new ServiceCollection();
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseDapr(client => client.AppId = DEFAULT_APP_ID);
callerBuilder.UseDapr(client => client.AppId = DEFAULT_APP_ID);
});

var serviceProvider = services.BuildServiceProvider();
Expand All @@ -37,9 +37,9 @@ public void TestAppIdByUseDaprAndAlwaysGetNewestDaprClient()
var services = new ServiceCollection();
var key = "callerBaseAddress" + Guid.NewGuid();
Environment.SetEnvironmentVariable(key, DEFAULT_APP_ID);
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseDapr(client =>
callerBuilder.UseDapr(client =>
{
client.AppId = Environment.GetEnvironmentVariable(key)!;
});
Expand Down Expand Up @@ -74,9 +74,9 @@ public void TestAppIdByUseDaprAndSetEnvironment()
var services = new ServiceCollection();
var actualAppId = Guid.NewGuid().ToString();
Environment.SetEnvironmentVariable(DEFAULT_APP_ID, actualAppId);
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseDapr(client => client.AppId = DEFAULT_APP_ID);
callerBuilder.UseDapr(client => client.AppId = DEFAULT_APP_ID);
});

var serviceProvider = services.BuildServiceProvider();
Expand All @@ -98,9 +98,9 @@ public void TestAppIdByUseDaprAndSetEnvironmentAndUseJsonConfig()

var actualAppId = Guid.NewGuid().ToString();
Environment.SetEnvironmentVariable(DEFAULT_APP_ID, actualAppId);
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseDapr(client => client.AppId = DEFAULT_APP_ID);
callerBuilder.UseDapr(client => client.AppId = DEFAULT_APP_ID);
});

var serviceProvider = services.BuildServiceProvider();
Expand All @@ -120,9 +120,9 @@ public void TestAppIdByUseDaprAndUseJsonConfig()
var services = new ServiceCollection();
AddJsonConfig(services);

services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseDapr(client => client.AppId = DEFAULT_APP_ID);
callerBuilder.UseDapr(client => client.AppId = DEFAULT_APP_ID);
});

var serviceProvider = services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class CallerTest

private const string FRAMEWORK_BASE_ADDRESS = "https://github.com/masastack/MASA.Framework";

private CallerBuilder _callerOptions;
private CallerBuilder _callerBuilder;
private const string NAME = "";

[TestInitialize]
public void Initialize()
{
var services = new ServiceCollection();
_callerOptions = new CallerBuilder(services, NAME);
_callerBuilder = new CallerBuilder(services, NAME);
}

[TestMethod]
Expand All @@ -34,12 +34,12 @@ public void TestUseHttpClient()
var docBaseAddress = "https://docs.masastack.com";
var key = "callerBaseAddress" + Guid.NewGuid();
Environment.SetEnvironmentVariable(key, FRAMEWORK_BASE_ADDRESS);
var masaHttpClientBuilder = _callerOptions.UseHttpClient(httpClient =>
var masaHttpClientBuilder = _callerBuilder.UseHttpClient(httpClient =>
{
httpClient.BaseAddress = Environment.GetEnvironmentVariable(key)!;
});
Assert.AreEqual(NAME, masaHttpClientBuilder.Name);
Assert.AreEqual(_callerOptions.Services, masaHttpClientBuilder.Services);
Assert.AreEqual(_callerBuilder.Services, masaHttpClientBuilder.Services);

var serviceProvider = masaHttpClientBuilder.Services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();
Expand All @@ -60,9 +60,9 @@ public void TestHttpClientByUseHttpClient()
Environment.SetEnvironmentVariable(key, FRAMEWORK_BASE_ADDRESS);

var services = new ServiceCollection();
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseHttpClient(client =>
callerBuilder.UseHttpClient(client =>
{
client.Prefix = "masa";
client.BaseAddress = Environment.GetEnvironmentVariable(key)!;
Expand Down Expand Up @@ -95,9 +95,9 @@ public void TestHttpClientByUseHttpClient()
public void TestMiddlewaresByUseHttpClient()
{
var services = new ServiceCollection();
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseHttpClient(client =>
callerBuilder.UseHttpClient(client =>
{
client.BaseAddress = FRAMEWORK_BASE_ADDRESS;
}).UseI18n();
Expand All @@ -116,9 +116,9 @@ public void TestMiddlewaresByUseHttpClient()
public void TestRequestMessageByUseHttpClient()
{
var services = new ServiceCollection();
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseHttpClient(client =>
callerBuilder.UseHttpClient(client =>
{
client.BaseAddress = FRAMEWORK_BASE_ADDRESS;
});
Expand All @@ -145,9 +145,9 @@ public void TestRequestMessageByUseHttpClient()
public void TestCustomRequestMessageByUseHttpClient()
{
var services = new ServiceCollection();
services.AddCaller(callerOptions =>
services.AddCaller(callerBuilder =>
{
callerOptions.UseHttpClient(client =>
callerBuilder.UseHttpClient(client =>
{
client.UseXml();
client.BaseAddress = FRAMEWORK_BASE_ADDRESS;
Expand Down
Loading