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
2e6a6ec7
Commit
2e6a6ec7
authored
Jun 01, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
bc36b3d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
114 deletions
+0
-114
ConsistencyBuilder.cs
src/Cap.Consistency/Builder/ConsistencyBuilder.cs
+0
-107
ConsistencyMarkerService.cs
src/Cap.Consistency/Builder/ConsistencyMarkerService.cs
+0
-7
No files found.
src/Cap.Consistency/Builder/ConsistencyBuilder.cs
deleted
100644 → 0
View file @
bc36b3d4
using
System
;
using
System.Reflection
;
using
System.Collections.Concurrent
;
using
System.Linq
;
using
Microsoft.Extensions.DependencyInjection
;
using
System.Collections.Generic
;
using
Cap.Consistency.Consumer
;
using
Cap.Consistency.Routing
;
using
Cap.Consistency.Infrastructure
;
using
Cap.Consistency.Internal
;
using
Cap.Consistency.Abstractions
;
namespace
Cap.Consistency
{
/// <summary>
/// Helper functions for configuring consistency services.
/// </summary>
public
class
ConsistencyBuilder
{
/// <summary>
/// Creates a new instance of <see cref="ConsistencyBuilder"/>.
/// </summary>
/// <param name="message">The <see cref="Type"/> to use for the message.</param>
/// <param name="service">The <see cref="IServiceCollection"/> to attach to.</param>
public
ConsistencyBuilder
(
Type
message
,
IServiceCollection
service
)
{
MessageType
=
message
;
Services
=
service
;
AddConsumerServices
();
}
/// <summary>
/// Gets the <see cref="IServiceCollection"/> services are attached to.
/// </summary>
/// <value>
/// The <see cref="IServiceCollection"/> services are attached to.
/// </value>
public
IServiceCollection
Services
{
get
;
private
set
;
}
/// <summary>
/// Gets the <see cref="Type"/> used for messages.
/// </summary>
/// <value>
/// The <see cref="Type"/> used for messages.
/// </value>
public
Type
MessageType
{
get
;
private
set
;
}
public
virtual
ConsistencyBuilder
AddConsumerServices
()
{
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
.
AddSingleton
<
IConsumerExcutorSelector
,
ConsumerExcutorSelector
>();
Services
.
AddSingleton
<
IConsumerInvokerFactory
,
ConsumerInvokerFactory
>();
Services
.
AddSingleton
<
MethodMatcherCache
>();
Services
.
AddSingleton
(
typeof
(
ITopicRoute
),
typeof
(
ConsumerHandler
<>).
MakeGenericType
(
MessageType
));
return
this
;
}
/// <summary>
/// Adds a <see cref="IConsistencyMessageStore{TMessage}"/> for the <seealso cref="MessageType"/>.
/// </summary>
/// <typeparam name="T">The role type held in the store.</typeparam>
/// <returns>The current <see cref="ConsistencyBuilder"/> instance.</returns>
public
virtual
ConsistencyBuilder
AddMessageStore
<
T
>()
where
T
:
class
{
return
AddScoped
(
typeof
(
IConsistencyMessageStore
<>).
MakeGenericType
(
MessageType
),
typeof
(
T
));
}
/// <summary>
/// Adds a <see cref="ConsistencyMessageManager{TUser}"/> for the <seealso cref="MessageType"/>.
/// </summary>
/// <typeparam name="TMessageManager">The type of the message manager to add.</typeparam>
/// <returns>The current <see cref="ConsistencyBuilder"/> instance.</returns>
public
virtual
ConsistencyBuilder
AddConsistencyMessageManager
<
TMessageManager
>()
where
TMessageManager
:
class
{
var
messageManagerType
=
typeof
(
ConsistencyMessageManager
<>).
MakeGenericType
(
MessageType
);
var
customType
=
typeof
(
TMessageManager
);
if
(
messageManagerType
==
customType
||
!
messageManagerType
.
GetTypeInfo
().
IsAssignableFrom
(
customType
.
GetTypeInfo
()))
{
throw
new
InvalidOperationException
(
$"Type
{
customType
.
Name
}
must be derive from ConsistencyMessageManager<
{
MessageType
.
Name
}
>"
);
}
Services
.
AddScoped
(
customType
,
services
=>
services
.
GetRequiredService
(
messageManagerType
));
return
AddScoped
(
messageManagerType
,
customType
);
}
private
ConsistencyBuilder
AddScoped
(
Type
serviceType
,
Type
concreteType
)
{
Services
.
AddScoped
(
serviceType
,
concreteType
);
return
this
;
}
}
}
\ No newline at end of file
src/Cap.Consistency/Builder/ConsistencyMarkerService.cs
deleted
100644 → 0
View file @
bc36b3d4
namespace
Cap.Consistency
{
/// <summary>
/// Used to verify Consistency service was called on a ServiceCollection
/// </summary>
public
class
ConsistencyMarkerService
{
}
}
\ 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