Browse Source

add config options fiels

master
yangxiaodong 8 years ago
parent
commit
ccc41b7204
6 changed files with 58 additions and 7 deletions
  1. +13
    -0
      src/Cap.Consistency/BrokerOptions.cs
  2. +2
    -2
      src/Cap.Consistency/BuilderExtensions.cs
  3. +2
    -4
      src/Cap.Consistency/Cap.Consistency.xproj
  4. +21
    -0
      src/Cap.Consistency/ConsistencyOptions.cs
  5. +19
    -1
      src/Cap.Consistency/ServiceCollectionExtensions.cs
  6. +1
    -0
      src/Cap.Consistency/project.json

+ 13
- 0
src/Cap.Consistency/BrokerOptions.cs View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Cap.Consistency
{

public class BrokerOptions
{

}
}

+ 2
- 2
src/Cap.Consistency/BuilderExtensions.cs View File

@@ -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;


+ 2
- 4
src/Cap.Consistency/Cap.Consistency.xproj View File

@@ -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>

+ 21
- 0
src/Cap.Consistency/ConsistencyOptions.cs View File

@@ -0,0 +1,21 @@
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();
}
}

+ 19
- 1
src/Cap.Consistency/ServiceCollectionExtensions.cs View File

@@ -1,5 +1,7 @@
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);
}
}

+ 1
- 0
src/Cap.Consistency/project.json View File

@@ -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"


Loading…
Cancel
Save