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
eda2ef13
Commit
eda2ef13
authored
Jun 05, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
e136a056
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
+95
-0
ConsistencyBuilder.cs
...soft.Extensions.DependencyInjection/ConsistencyBuilder.cs
+16
-0
ServiceCollectionExtensions.cs
...nsions.DependencyInjection/ServiceCollectionExtensions.cs
+79
-0
No files found.
src/Cap.Consistency/Microsoft.Extensions.DependencyInjection/ConsistencyBuilder.cs
0 → 100644
View file @
eda2ef13
namespace
Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Used to verify Consistency service was called on a ServiceCollection
/// </summary>
public
class
ConsistencyMarkerService
{
}
public
class
ConsistencyBuilder
{
public
ConsistencyBuilder
(
IServiceCollection
services
)
{
Services
=
services
;
}
public
IServiceCollection
Services
{
get
;
private
set
;
}
}
}
\ No newline at end of file
src/Cap.Consistency/Microsoft.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
0 → 100644
View file @
eda2ef13
using
System
;
using
System.Collections.Generic
;
using
System.Reflection
;
using
Cap.Consistency
;
using
Cap.Consistency.Abstractions.ModelBinding
;
using
Cap.Consistency.Consumer
;
using
Cap.Consistency.Infrastructure
;
using
Cap.Consistency.Internal
;
using
Cap.Consistency.Store
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
// ReSharper disable once CheckNamespace
namespace
Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Contains extension methods to <see cref="IServiceCollection"/> for configuring consistence services.
/// </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="ConsistencyBuilder"/> for application services.</returns>
public
static
ConsistencyBuilder
AddConsistency
(
this
IServiceCollection
services
)
{
services
.
AddConsistency
(
x
=>
new
ConsistencyOptions
());
return
new
ConsistencyBuilder
(
services
);
}
/// <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
(
this
IServiceCollection
services
,
Action
<
ConsistencyOptions
>
setupAction
)
{
services
.
TryAddSingleton
<
ConsistencyMarkerService
>();
services
.
TryAddSingleton
<
ConsistencyMessageManager
>();
services
.
Configure
(
setupAction
);
var
IConsumerListenerServices
=
new
Dictionary
<
Type
,
Type
>();
foreach
(
var
rejectedServices
in
services
)
{
if
(
rejectedServices
.
ImplementationType
!=
null
&&
typeof
(
IConsumerService
).
IsAssignableFrom
(
rejectedServices
.
ImplementationType
))
IConsumerListenerServices
.
Add
(
typeof
(
IConsumerService
),
rejectedServices
.
ImplementationType
);
}
foreach
(
var
service
in
IConsumerListenerServices
)
{
services
.
AddSingleton
(
service
.
Key
,
service
.
Value
);
}
var
types
=
Assembly
.
GetEntryAssembly
().
ExportedTypes
;
foreach
(
var
type
in
types
)
{
if
(
typeof
(
IConsumerService
).
IsAssignableFrom
(
type
))
{
services
.
AddSingleton
(
typeof
(
IConsumerService
),
type
);
}
}
services
.
TryAddSingleton
<
IConsumerExcutorSelector
,
ConsumerExcutorSelector
>();
services
.
TryAddSingleton
<
IModelBinder
,
DefaultModelBinder
>();
services
.
TryAddSingleton
<
IConsumerInvokerFactory
,
ConsumerInvokerFactory
>();
services
.
TryAddSingleton
<
MethodMatcherCache
>();
services
.
TryAddSingleton
(
typeof
(
ITopicRouteHandler
),
typeof
(
ConsumerHandler
));
return
new
ConsistencyBuilder
(
services
);
}
public
static
ConsistencyBuilder
AddMessageStore
<
T
>(
this
ConsistencyBuilder
build
)
where
T
:
class
,
IConsistencyMessageStore
{
build
.
Services
.
AddScoped
<
IConsistencyMessageStore
,
T
>();
return
build
;
}
}
}
\ No newline at end of file
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