-
Notifications
You must be signed in to change notification settings - Fork 307
Revisit IServerFactory.Start #395
Comments
Well as a factory it can be used more than once (not that we actually do this at the moment). Maybe a factory isn't the pattern you want here? Removing that param makes it a statefull single use class. At that point you would just make the factory itself disposable rather than returning anything from start. |
public interface IServerFactory : IDisposable
{
IFeatureCollection Initialize(IConfiguration configuration);
void Start(Func<IFeatureCollection, Task> application);
} I'm not sure. I guess it does feel a bit off that some of those things are inferred (e.g. the fact that the returned IFeatureCollection should be used later by Start?) |
How about: public interface IServer : IDisposable
{
IFeatureCollection Features { get; }
void Initialize(IConfiguration configuration);
void Start(Func<IFeatureCollection, Task> application);
} Note initialize only exists in this model because we don't have a good way of getting the IConfiguration into the DI constructor. |
What about: public interface IServerFactory
{
IServer CreateServer(IConfiguration configuration);
} public interface IServer : IDisposable
{
IFeatureCollection Features { get; }
void Start(Func<IFeatureCollection, Task> application);
} |
shrug we can try it. I don't think it solves any issues, it's just API cleanup. |
This whole issue is about API cleanup. I was demoing the interface recently and decided to file this issue because I thought the stateless nature of the server factory was a little weird. |
After discussion with @lodejard @davidfowl , slight change: public interface IServerFactory
{
IServer CreateServer(IConfiguration configuration);
} public interface IServer : IDisposable
{
IFeatureCollection Features { get; }
void Start(RequestDelegate requestDelegate);
} |
RequestDelegate takes an HttpContext, not an IFeatureCollection. Hosting creates the HttpContext, not the server. |
I think @davidfowl or @lodejard requested that change from IFeatureCollection to HttpContext, but I didn't quite get why. |
We're unifying the signatures. Everything is HttpContext now and the feature collection becomes and implementation detail of the HttpContextFactory. The layers have been mushed. |
This looks pretty similar to all of the builders we have Maybe?
|
Except there's nothing to hang off of it. |
So the distinction is that Builder means a fancy Factory that has knobs/settings that you can adjust before calling build? |
Yah. We aren't actually building/configuring anything just making a sever instance |
merged to dev |
--updated from pull request comments As per emails, the new proposal is as follows: namespace Microsoft.AspNet.Server.Abstractions
{
public interface IHttpApplication<THttpContext>
{
THttpContext CreateContext(IFeatureCollection contextFeatures);
Task ProcessRequestAsync(THttpContext httpContext);
void DisposeContext(THttpContext httpContext, Exception exception);
}
public interface IServerFactory
{
IServer CreateServer(IConfiguration configuration);
}
public interface IServer : IDisposable
{
void Start<THttpContext>(IHttpApplication<THttpContext> application);
}
}
public class HostingApplication : IHttpApplication<HostingApplication.Context>
{
Context CreateContext(IFeatureCollection contextFeatures) { ... }
Task ProcessRequestAsync(Context context) { ... }
void DisposeContext(Context context, Exception exception) { ... }
public struct Context
{
public HttpContext HttpContext { get; set; }
public IDisposable Scope { get; set; }
public int TickCount { get; set; }
}
} |
Updated the spec |
1 similar comment
Updated the spec |
While looking to adapt the Kestrel server to the new spec, I found that the generic typing is causing us to make many function calls/callbacks to become generic, see aspnet/KestrelHttpServer@3077b96. Maybe we should just use object instead? |
👍 for using object over trying to flow the generic parameter. |
Moar updates to the design! Instead of using object, we'll use generics but modify Kestrel's design a bit to make the generic propagation less viral. |
Does it really need to pass back in the IFeatureCollection returned in Initialize?
Why not just:
The current design does allow you to pass in different instances but I'm not sure if that's a goal since we don't use it that way currently.
The text was updated successfully, but these errors were encountered: