Commit ccc41b72 authored by yangxiaodong's avatar yangxiaodong

add config options fiels

parent 11102034
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Cap.Consistency
{
public class BrokerOptions
{
}
}
......@@ -15,14 +15,14 @@ namespace Microsoft.AspNetCore.Builder
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
/// <returns>The <see cref="IApplicationBuilder"/> instance this method extends.</returns>
public static IApplicationBuilder UseKafkaConsistence(this IApplicationBuilder app) {
public static IApplicationBuilder UseConsistency(this IApplicationBuilder app) {
if (app == null) {
throw new ArgumentNullException(nameof(app));
}
var marker = app.ApplicationServices.GetService<ConsistencyMarkerService>();
if (marker == null) {
throw new InvalidOperationException("AddKafkaConsistence must be called on the service collection.");
throw new InvalidOperationException("Add Consistency must be called on the service collection.");
}
return app;
......
......@@ -4,18 +4,16 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>e8af8611-0ea4-4b19-bc48-87c57a87dc66</ProjectGuid>
<RootNamespace>KafkaConsistence</RootNamespace>
<RootNamespace>Cap.Consistency</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
\ No newline at end of file
using Cap.Consistency;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Represents all the options you can use to configure the system.
/// </summary>
public class ConsistencyOptions
{
/// <summary>
/// Gets or sets the <see cref="BrokerOptions"/> for the consistency system.
/// </summary>
public BrokerOptions Broker { get; set; } = new BrokerOptions();
}
}
using Cap.Consistency;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
......@@ -9,18 +11,34 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds and configures the consistence services for the consitence.
/// </summary>
/// <param name="services">The services available in the application.</param>
/// <returns>An <see cref="IServiceCollection"/> for application services.</returns>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
public static ConsistencyBuilder AddConsistency<TMessage>(this IServiceCollection services)
where TMessage : class {
return services.AddConsistency<TMessage>(setupAction: null);
}
/// <summary>
/// Adds and configures the consistence services for the consitence.
/// </summary>
/// <param name="services">The services available in the application.</param>
/// <param name="setupAction">An action to configure the <see cref="ConsistencyOptions"/>.</param>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
public static ConsistencyBuilder AddConsistency<TMessage>(this IServiceCollection services, Action<ConsistencyOptions> setupAction)
where TMessage : class {
services.TryAddSingleton<ConsistencyMarkerService>();
services.TryAddScoped<ConsistencyMessageManager<TMessage>, ConsistencyMessageManager<TMessage>>();
if (setupAction != null) {
services.Configure(setupAction);
}
return new ConsistencyBuilder(typeof(TMessage), services);
}
}
......
......@@ -2,6 +2,7 @@
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*",
"Microsoft.Extensions.Options": "1.1.0-*",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.1.0",
"Microsoft.Extensions.Logging.Abstractions": "1.1.0-*",
"NETStandard.Library": "1.6.1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment