Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
c04f65c8
Commit
c04f65c8
authored
May 16, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
c1b1509e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
32 deletions
+9
-32
BuilderExtensions.cs
src/Cap.Consistency/Extensions/BuilderExtensions.cs
+5
-19
ConsistencyOptions.cs
src/Cap.Consistency/Extensions/ConsistencyOptions.cs
+1
-9
ServiceCollectionExtensions.cs
...Cap.Consistency/Extensions/ServiceCollectionExtensions.cs
+3
-4
No files found.
src/Cap.Consistency/Extensions/BuilderExtensions.cs
View file @
c04f65c8
...
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Builder
...
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Builder
/// </summary>
/// </summary>
public
static
class
BuilderExtensions
public
static
class
BuilderExtensions
{
{
///
<summary>
///<summary>
/// Enables Consistence for the current application
/// Enables Consistence for the current application
/// </summary>
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
...
@@ -20,34 +20,20 @@ namespace Microsoft.AspNetCore.Builder
...
@@ -20,34 +20,20 @@ namespace Microsoft.AspNetCore.Builder
if
(
app
==
null
)
{
if
(
app
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
app
));
throw
new
ArgumentNullException
(
nameof
(
app
));
}
}
var
marker
=
app
.
ApplicationServices
.
GetService
<
ConsistencyMarkerService
>();
var
marker
=
app
.
ApplicationServices
.
GetService
<
ConsistencyMarkerService
>();
if
(
marker
==
null
)
{
if
(
marker
==
null
)
{
throw
new
InvalidOperationException
(
"Add Consistency must be called on the service collection."
);
throw
new
InvalidOperationException
(
"Add Consistency must be called on the service collection."
);
}
}
return
app
;
var
router
=
app
.
ApplicationServices
.
GetService
<
ITopicRoute
>();
}
public
static
IApplicationBuilder
UserRouter
(
this
IApplicationBuilder
builder
,
ITopicRoute
router
)
{
if
(
builder
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
builder
));
}
if
(
router
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
router
));
}
var
marker
=
builder
.
ApplicationServices
.
GetService
<
ConsistencyMarkerService
>();
if
(
marker
==
null
)
{
throw
new
InvalidOperationException
(
"Add Consistency must be called on the service collection."
);
}
var
context
=
new
TopicRouteContext
();
var
context
=
new
TopicRouteContext
();
router
.
RouteAsync
(
context
).
Wait
();
router
.
RouteAsync
(
context
).
Wait
();
return
builder
;
return
app
;
}
}
}
}
...
...
src/Cap.Consistency/Extensions/ConsistencyOptions.cs
View file @
c04f65c8
...
@@ -7,14 +7,6 @@ namespace Microsoft.AspNetCore.Builder
...
@@ -7,14 +7,6 @@ namespace Microsoft.AspNetCore.Builder
/// </summary>
/// </summary>
public
class
ConsistencyOptions
public
class
ConsistencyOptions
{
{
/// <summary>
public
string
BrokerUrlList
{
get
;
set
;
}
=
"localhost:9092"
;
/// Gets or sets the <see cref="BrokerOptions"/> for the consistency system.
/// </summary>
public
BrokerOptions
Broker
{
get
;
set
;
}
=
new
BrokerOptions
();
public
string
BrokerUrlList
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
src/Cap.Consistency/Extensions/ServiceCollectionExtensions.cs
View file @
c04f65c8
using
System
;
using
System
;
using
Cap.Consistency
;
using
Cap.Consistency
;
using
Cap.Consistency.Infrastructure
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
...
@@ -17,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -17,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="services">The services available in the application.</param>
/// <param name="services">The services available in the application.</param>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
public
static
ConsistencyBuilder
AddConsistency
<
TMessage
>(
this
IServiceCollection
services
)
public
static
ConsistencyBuilder
AddConsistency
<
TMessage
>(
this
IServiceCollection
services
)
where
TMessage
:
class
{
where
TMessage
:
ConsistencyMessage
{
return
services
.
AddConsistency
<
TMessage
>(
setupAction
:
null
);
return
services
.
AddConsistency
<
TMessage
>(
setupAction
:
null
);
}
}
...
@@ -28,13 +29,11 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -28,13 +29,11 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="setupAction">An action to configure the <see cref="ConsistencyOptions"/>.</param>
/// <param name="setupAction">An action to configure the <see cref="ConsistencyOptions"/>.</param>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
public
static
ConsistencyBuilder
AddConsistency
<
TMessage
>(
this
IServiceCollection
services
,
Action
<
ConsistencyOptions
>
setupAction
)
public
static
ConsistencyBuilder
AddConsistency
<
TMessage
>(
this
IServiceCollection
services
,
Action
<
ConsistencyOptions
>
setupAction
)
where
TMessage
:
class
{
where
TMessage
:
ConsistencyMessage
{
services
.
TryAddSingleton
<
ConsistencyMarkerService
>();
services
.
TryAddSingleton
<
ConsistencyMarkerService
>();
services
.
TryAddScoped
<
ConsistencyMessageManager
<
TMessage
>,
ConsistencyMessageManager
<
TMessage
>>();
services
.
TryAddScoped
<
ConsistencyMessageManager
<
TMessage
>,
ConsistencyMessageManager
<
TMessage
>>();
services
.
AddSingleton
<
KafkaConsistency
>();
if
(
setupAction
!=
null
)
{
if
(
setupAction
!=
null
)
{
services
.
Configure
(
setupAction
);
services
.
Configure
(
setupAction
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment