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
da57138b
Commit
da57138b
authored
Jun 21, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add jobs services to DI.
parent
d52ce288
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
25 deletions
+66
-25
ConsistencyBuilder.cs
...soft.Extensions.DependencyInjection/ConsistencyBuilder.cs
+34
-1
ServiceCollectionExtensions.cs
...nsions.DependencyInjection/ServiceCollectionExtensions.cs
+32
-24
No files found.
src/Cap.Consistency/Microsoft.Extensions.DependencyInjection/ConsistencyBuilder.cs
View file @
da57138b
namespace
Microsoft.Extensions.DependencyInjection
using
System
;
using
Cap.Consistency.Job
;
using
Cap.Consistency.Store
;
namespace
Microsoft.Extensions.DependencyInjection
{
{
/// <summary>
/// <summary>
/// Used to verify Consistency service was called on a ServiceCollection
/// Used to verify Consistency service was called on a ServiceCollection
...
@@ -12,5 +16,34 @@
...
@@ -12,5 +16,34 @@
}
}
public
IServiceCollection
Services
{
get
;
private
set
;
}
public
IServiceCollection
Services
{
get
;
private
set
;
}
private
ConsistencyBuilder
AddScoped
(
Type
serviceType
,
Type
concreteType
)
{
Services
.
AddScoped
(
serviceType
,
concreteType
);
return
this
;
}
private
ConsistencyBuilder
AddSingleton
<
TService
,
TImplementation
>()
where
TService
:
class
where
TImplementation
:
class
,
TService
{
Services
.
AddSingleton
<
TService
,
TImplementation
>();
return
this
;
}
/// <summary>
/// Adds an <see cref="IConsistencyMessageStore"/> .
/// </summary>
/// <typeparam name="T">The type for the <see cref="IConsistencyMessageStore"/> to add. </typeparam>
/// <returns>The current <see cref="ConsistencyBuilder"/> instance.</returns>
public
virtual
ConsistencyBuilder
AddMessageStore
<
T
>()
where
T
:
class
,
IConsistencyMessageStore
{
return
AddScoped
(
typeof
(
IConsistencyMessageStore
),
typeof
(
T
));
}
public
virtual
ConsistencyBuilder
AddJobs
<
T
>()
where
T
:
class
,
IJob
{
return
AddSingleton
<
IJob
,
T
>();
}
}
}
}
}
\ No newline at end of file
src/Cap.Consistency/Microsoft.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
View file @
da57138b
...
@@ -6,10 +6,10 @@ using Cap.Consistency.Abstractions.ModelBinding;
...
@@ -6,10 +6,10 @@ using Cap.Consistency.Abstractions.ModelBinding;
using
Cap.Consistency.Consumer
;
using
Cap.Consistency.Consumer
;
using
Cap.Consistency.Infrastructure
;
using
Cap.Consistency.Infrastructure
;
using
Cap.Consistency.Internal
;
using
Cap.Consistency.Internal
;
using
Cap.Consistency.Job
;
using
Cap.Consistency.Store
;
using
Cap.Consistency.Store
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
// ReSharper disable once CheckNamespace
namespace
Microsoft.Extensions.DependencyInjection
namespace
Microsoft.Extensions.DependencyInjection
{
{
/// <summary>
/// <summary>
...
@@ -34,18 +34,43 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -34,18 +34,43 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="services">The services available in the application.</param>
/// <param name="services">The services available in the application.</param>
/// <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
(
this
IServiceCollection
services
,
Action
<
ConsistencyOptions
>
setupAction
)
{
public
static
ConsistencyBuilder
AddConsistency
(
services
.
TryAddSingleton
<
ConsistencyMarkerService
>();
this
IServiceCollection
services
,
Action
<
ConsistencyOptions
>
setupAction
)
{
services
.
TryAddSingleton
<
ConsistencyMarkerService
>();
services
.
Configure
(
setupAction
);
services
.
Configure
(
setupAction
);
var
IConsumerListenerServices
=
new
Dictionary
<
Type
,
Type
>();
AddConsumerServices
(
services
);
services
.
TryAddSingleton
<
IConsumerExcutorSelector
,
ConsumerExcutorSelector
>();
services
.
TryAddSingleton
<
IModelBinder
,
DefaultModelBinder
>();
services
.
TryAddSingleton
<
IConsumerInvokerFactory
,
ConsumerInvokerFactory
>();
services
.
TryAddSingleton
<
MethodMatcherCache
>();
services
.
TryAddScoped
<
ConsistencyMessageManager
>();
services
.
AddSingleton
<
IProcessingServer
,
ConsumerHandler
>();
services
.
AddSingleton
<
IProcessingServer
,
JobProcessingServer
>();
services
.
AddSingleton
<
IBootstrapper
,
DefaultBootstrapper
>();
services
.
TryAddTransient
<
IJobProcessor
,
CronJobProcessor
>();
services
.
TryAddSingleton
<
IJob
,
CapJob
>();
services
.
TryAddTransient
<
DefaultCronJobRegistry
>();
return
new
ConsistencyBuilder
(
services
);
}
private
static
void
AddConsumerServices
(
IServiceCollection
services
)
{
var
consumerListenerServices
=
new
Dictionary
<
Type
,
Type
>();
foreach
(
var
rejectedServices
in
services
)
{
foreach
(
var
rejectedServices
in
services
)
{
if
(
rejectedServices
.
ImplementationType
!=
null
&&
typeof
(
IConsumerService
).
IsAssignableFrom
(
rejectedServices
.
ImplementationType
))
if
(
rejectedServices
.
ImplementationType
!=
null
IConsumerListenerServices
.
Add
(
typeof
(
IConsumerService
),
rejectedServices
.
ImplementationType
);
&&
typeof
(
IConsumerService
).
IsAssignableFrom
(
rejectedServices
.
ImplementationType
))
consumerListenerServices
.
Add
(
typeof
(
IConsumerService
),
rejectedServices
.
ImplementationType
);
}
}
foreach
(
var
service
in
IC
onsumerListenerServices
)
{
foreach
(
var
service
in
c
onsumerListenerServices
)
{
services
.
AddSingleton
(
service
.
Key
,
service
.
Value
);
services
.
AddSingleton
(
service
.
Key
,
service
.
Value
);
}
}
...
@@ -55,23 +80,6 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -55,23 +80,6 @@ namespace Microsoft.Extensions.DependencyInjection
services
.
AddSingleton
(
typeof
(
IConsumerService
),
type
);
services
.
AddSingleton
(
typeof
(
IConsumerService
),
type
);
}
}
}
}
services
.
TryAddSingleton
<
IConsumerExcutorSelector
,
ConsumerExcutorSelector
>();
services
.
TryAddSingleton
<
IModelBinder
,
DefaultModelBinder
>();
services
.
TryAddSingleton
<
IConsumerInvokerFactory
,
ConsumerInvokerFactory
>();
services
.
TryAddSingleton
<
MethodMatcherCache
>();
services
.
TryAddSingleton
(
typeof
(
ITopicServer
),
typeof
(
ConsumerHandler
));
return
new
ConsistencyBuilder
(
services
);
}
public
static
ConsistencyBuilder
AddMessageStore
<
T
>(
this
ConsistencyBuilder
build
)
where
T
:
class
,
IConsistencyMessageStore
{
build
.
Services
.
AddScoped
<
IConsistencyMessageStore
,
T
>();
build
.
Services
.
TryAddScoped
<
ConsistencyMessageManager
>();
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