[ https://issues.apache.org/jira/browse/LUCENENET-565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16105306#comment-16105306
]
ASF GitHub Bot commented on LUCENENET-565:
------------------------------------------
Github user AndyPook commented on the issue:
https://github.com/apache/lucenenet/pull/209
just playing... here's how a middleware might look
```csharp
public class Startup
{
// usual boiler plate
// add some method that bootstraps the index and replication service
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory
loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseLuceneReplicator("/_replicator", "replicaService123");
app.UseMvc();
}
}
// these bits live in Lucene.Net.Replicator.AspNetCore
public static class LuceneReplicatorMiddlewareExtensions
{
public static IApplicationBuilder UseLuceneReplicator(this IApplicationBuilder builder,
PathString prefix, object replicaService)
{
return builder.Map(prefix, app => app.UseMiddleware<LuceneReplicatorMiddleware>(replicaService));
}
}
public class LuceneReplicatorMiddleware
{
private readonly RequestDelegate next;
private readonly object replicaService;
public LuceneReplicatorMiddleware(RequestDelegate next, object replicaService)
{
this.next = next;
this.replicaService= replicaService;
}
public async Task Invoke(HttpContext context)
{
var req = context.Request;
await context.Response.WriteAsync($"<p>{DateTime.Now.ToString()}</p>");
await context.Response.WriteAsync($"<p>replicaService={replicaService.ToString()}</p>");
await context.Response.WriteAsync($"<p>path={req.Path}</p>");
await context.Response.WriteAsync($"<ul>");
foreach(var q in req.Query)
await context.Response.WriteAsync($"<li>{q.Key}={q.Value}</li>");
await context.Response.WriteAsync($"</ul>");
}
}
```
```app.Map``` intercepts requests with that prefix (they call it "branching the request
pipeline")
Where I've used "replicaService123" is just a demo of how to pass stuff into the middleware.
You'd substitute the ```ReplicationService```. Then ```Invoke``` could be as simple as ```replicaService.Perform(context.Request,
context.Response)```. But it might be better to pull the exception handling part out into
the middleware and just pass the response stream into the service.
Note: ```req.Path``` is just the part coming after the prefix
Anyway, just an idea
> Port Lucene.Net.Replicator
> --------------------------
>
> Key: LUCENENET-565
> URL: https://issues.apache.org/jira/browse/LUCENENET-565
> Project: Lucene.Net
> Issue Type: Task
> Components: Lucene.Net.Replicator
> Affects Versions: Lucene.Net 4.8.0
> Reporter: Shad Storhaug
> Priority: Minor
> Labels: features
>
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
|