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
9424cfd7
Commit
9424cfd7
authored
Aug 17, 2018
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Instead of manually configuring app.UseCAP using StartupFilter injection
parent
690380a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
CAP.AppBuilderExtensions.cs
src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs
+15
-1
CAP.ServiceCollectionExtensions.cs
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
+15
-12
No files found.
src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs
View file @
9424cfd7
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
using
System
;
using
System
;
using
DotNetCore.CAP
;
using
DotNetCore.CAP
;
using
DotNetCore.CAP.Dashboard.GatewayProxy
;
using
DotNetCore.CAP.Dashboard.GatewayProxy
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection
;
// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace
...
@@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.Builder
...
@@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.Builder
/// <summary>
/// <summary>
/// app extensions for <see cref="IApplicationBuilder" />
/// app extensions for <see cref="IApplicationBuilder" />
/// </summary>
/// </summary>
public
static
class
AppBuilderExtensions
internal
static
class
AppBuilderExtensions
{
{
/// <summary>
/// <summary>
/// Enables cap for the current application
/// Enables cap for the current application
...
@@ -70,4 +71,17 @@ namespace Microsoft.AspNetCore.Builder
...
@@ -70,4 +71,17 @@ namespace Microsoft.AspNetCore.Builder
}
}
}
}
}
}
sealed
class
CapStartupFilter
:
IStartupFilter
{
public
Action
<
IApplicationBuilder
>
Configure
(
Action
<
IApplicationBuilder
>
next
)
{
return
app
=>
{
app
.
UseCap
();
next
(
app
);
};
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
View file @
9424cfd7
...
@@ -8,6 +8,8 @@ using DotNetCore.CAP.Abstractions;
...
@@ -8,6 +8,8 @@ using DotNetCore.CAP.Abstractions;
using
DotNetCore.CAP.Internal
;
using
DotNetCore.CAP.Internal
;
using
DotNetCore.CAP.Processor
;
using
DotNetCore.CAP.Processor
;
using
DotNetCore.CAP.Processor.States
;
using
DotNetCore.CAP.Processor.States
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace
...
@@ -24,9 +26,7 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -24,9 +26,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>
/// <param name="setupAction">An action to configure the <see cref="CapOptions" />.</param>
/// <param name="setupAction">An action to configure the <see cref="CapOptions" />.</param>
/// <returns>An <see cref="CapBuilder" /> for application services.</returns>
/// <returns>An <see cref="CapBuilder" /> for application services.</returns>
public
static
CapBuilder
AddCap
(
public
static
CapBuilder
AddCap
(
this
IServiceCollection
services
,
Action
<
CapOptions
>
setupAction
)
this
IServiceCollection
services
,
Action
<
CapOptions
>
setupAction
)
{
{
if
(
setupAction
==
null
)
if
(
setupAction
==
null
)
{
{
...
@@ -36,6 +36,7 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -36,6 +36,7 @@ namespace Microsoft.Extensions.DependencyInjection
services
.
TryAddSingleton
<
CapMarkerService
>();
services
.
TryAddSingleton
<
CapMarkerService
>();
services
.
Configure
(
setupAction
);
services
.
Configure
(
setupAction
);
//Consumer service
AddSubscribeServices
(
services
);
AddSubscribeServices
(
services
);
//Serializer and model binder
//Serializer and model binder
...
@@ -49,18 +50,18 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -49,18 +50,18 @@ namespace Microsoft.Extensions.DependencyInjection
services
.
TryAddSingleton
<
MethodMatcherCache
>();
services
.
TryAddSingleton
<
MethodMatcherCache
>();
//Bootstrapper and Processors
//Bootstrapper and Processors
services
.
AddSingleton
<
IProcessingServer
,
ConsumerHandler
>(
);
services
.
TryAddEnumerable
(
ServiceDescriptor
.
Singleton
<
IProcessingServer
,
ConsumerHandler
>()
);
services
.
AddSingleton
<
IProcessingServer
,
CapProcessingServer
>(
);
services
.
TryAddEnumerable
(
ServiceDescriptor
.
Singleton
<
IProcessingServer
,
CapProcessingServer
>()
);
services
.
AddSingleton
<
IBootstrapper
,
DefaultBootstrapper
>();
services
.
Try
AddSingleton
<
IBootstrapper
,
DefaultBootstrapper
>();
services
.
AddSingleton
<
IStateChanger
,
StateChanger
>();
services
.
Try
AddSingleton
<
IStateChanger
,
StateChanger
>();
//Queue's message processor
//Queue's message processor
services
.
AddTransient
<
NeedRetryMessageProcessor
>();
services
.
TryAddSingleton
<
NeedRetryMessageProcessor
>();
//Sender and Executors
//Sender and Executors
services
.
AddSingleton
<
IDispatcher
,
Dispatcher
>();
services
.
Try
AddSingleton
<
IDispatcher
,
Dispatcher
>();
// Warning: IPublishMessageSender need to inject at extension project.
// Warning: IPublishMessageSender need to inject at extension project.
services
.
AddSingleton
<
ISubscriberExecutor
,
DefaultSubscriberExecutor
>();
services
.
Try
AddSingleton
<
ISubscriberExecutor
,
DefaultSubscriberExecutor
>();
//Options and extension service
//Options and extension service
var
options
=
new
CapOptions
();
var
options
=
new
CapOptions
();
...
@@ -69,9 +70,11 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -69,9 +70,11 @@ namespace Microsoft.Extensions.DependencyInjection
{
{
serviceExtension
.
AddServices
(
services
);
serviceExtension
.
AddServices
(
services
);
}
}
services
.
AddSingleton
(
options
);
services
.
AddSingleton
(
options
);
//Startup and Middleware
services
.
AddTransient
<
IStartupFilter
,
CapStartupFilter
>();
return
new
CapBuilder
(
services
);
return
new
CapBuilder
(
services
);
}
}
...
@@ -90,7 +93,7 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -90,7 +93,7 @@ namespace Microsoft.Extensions.DependencyInjection
foreach
(
var
service
in
consumerListenerServices
)
foreach
(
var
service
in
consumerListenerServices
)
{
{
services
.
AddTransient
(
service
.
Key
,
service
.
Value
);
services
.
TryAddEnumerable
(
ServiceDescriptor
.
Transient
(
service
.
Key
,
service
.
Value
)
);
}
}
}
}
}
}
...
...
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