https://github.com/joncloud/apogee-net
Allows activity to be batched together in the background
https://github.com/joncloud/apogee-net
activity asp-net-core asp-net-core-mvc background batch batching group mvc
Last synced: about 2 months ago
JSON representation
Allows activity to be batched together in the background
- Host: GitHub
- URL: https://github.com/joncloud/apogee-net
- Owner: joncloud
- License: mit
- Created: 2017-12-06T21:57:51.000Z (about 8 years ago)
- Default Branch: publish
- Last Pushed: 2020-06-13T21:56:08.000Z (over 5 years ago)
- Last Synced: 2025-03-06T04:36:32.151Z (11 months ago)
- Topics: activity, asp-net-core, asp-net-core-mvc, background, batch, batching, group, mvc
- Language: C#
- Size: 17.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Apogee.NET
[](https://travis-ci.org/joncloud/apogee-net/)
[](https://www.nuget.org/packages/Apogee/)
## Description
Apogee.NET allows activity to be batched together in the background.
## Licensing
Released under the MIT License. See the [LICENSE][] file for further details.
[license]: LICENSE.md
## Installation
In the Package Manager Console execute
```powershell
Install-Package Apogee
```
Or update `*.csproj` to include a dependency on
```xml
```
## Usage
Use the `AddApogee` configuration method to define all batch processors. Follow up with the `UseApogee` method to ensure that the system is started when the application starts.
See the following example for tracking visitors to the web site. It takes any activity that occurs, and defers it to the background in a batch to prevent the activity from taking valuable time from the intent of the user.
```csharp
public void ConfigureServices(IServiceCollection services) =>
services.AddApogee(options => options.AddProcessorScoped());
public void Configure(IApplicationBuilder app, IHostingEnvironment env) =>
app.UseApogee().UseMvc();
class VisitorProcessor : IBatchProcessor {
readonly VisitorContext _context;
public VisitorProcessor(VisitorContext context) =>
_context = context;
public void Process(Batch batch) {
_context.Visitors.AddRange(batch.Items);
_context.SaveChanges();
}
}
class VisitorMiddleware {
readonly RequestDelegate _next;
readonly IBatchService _batchService;
public VisitorMiddleware(RequestDelegate next, IBatchService batchService) {
_next = next;
_batchService = batchService;
}
public Task InvokeAsync(HttpContext context) {
var visitor = new Visitor(context);
_batchService.Add(visitor);
return _next(context);
}
}
```
For additional usage see [Tests][].
[Tests]: tests/Apogee.Tests