Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Revisit IServerFactory.Start #395

Closed
davidfowl opened this issue Oct 10, 2015 · 22 comments
Closed

Revisit IServerFactory.Start #395

davidfowl opened this issue Oct 10, 2015 · 22 comments
Assignees
Milestone

Comments

@davidfowl
Copy link
Member

Does it really need to pass back in the IFeatureCollection returned in Initialize?

IDisposable Start(IFeatureCollection serverFeatures, Func<IFeatureCollection, Task> application);

Why not just:

IDisposable Start(Func<IFeatureCollection, Task> application);

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.

@Tratcher
Copy link
Member

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.

@davidfowl
Copy link
Member Author

Thats what I'm wondering. I know the pattern allows for that but I'm not sure we use it or plan to use it anywhere that way. I know this stuff came from katana but I'd like to understand if we ever plan to use it in that way in the current stack.

/cc @loudej @lodejard

@davidfowl
Copy link
Member Author

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?)

@Tratcher
Copy link
Member

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.

@davidfowl
Copy link
Member Author

What about:

public interface IServerFactory
{
    IServer CreateServer(IConfiguration configuration);
}
public interface IServer : IDisposable
{
    IFeatureCollection Features { get; }
    void Start(Func<IFeatureCollection, Task> application);
}

@Tratcher
Copy link
Member

shrug we can try it. I don't think it solves any issues, it's just API cleanup.

@davidfowl
Copy link
Member Author

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.

@Eilon
Copy link
Member

Eilon commented Oct 13, 2015

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);
}

@Tratcher
Copy link
Member

RequestDelegate takes an HttpContext, not an IFeatureCollection. Hosting creates the HttpContext, not the server.

@Eilon
Copy link
Member

Eilon commented Oct 13, 2015

I think @davidfowl or @lodejard requested that change from IFeatureCollection to HttpContext, but I didn't quite get why.

@davidfowl
Copy link
Member Author

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.

@HaoK
Copy link
Member

HaoK commented Oct 14, 2015

This looks pretty similar to all of the builders we have

Maybe?

public interface IServerBuilder
{
    IServer Build(IConfiguration configuration);
}

@davidfowl
Copy link
Member Author

Except there's nothing to hang off of it.

@HaoK
Copy link
Member

HaoK commented Oct 14, 2015

So the distinction is that Builder means a fancy Factory that has knobs/settings that you can adjust before calling build?

@davidfowl
Copy link
Member Author

Yah. We aren't actually building/configuring anything just making a sever instance

@muratg muratg removed this from the 1.0.0-rc1 milestone Oct 26, 2015
JunTaoLuo added a commit that referenced this issue Oct 28, 2015
JunTaoLuo added a commit that referenced this issue Oct 29, 2015
JunTaoLuo added a commit that referenced this issue Oct 30, 2015
@JunTaoLuo
Copy link
Contributor

merged to dev

@JunTaoLuo
Copy link
Contributor

--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; }
    }
}

cc @davidfowl @lodejard @Tratcher @troydai @rynowak

@davidfowl
Copy link
Member Author

Updated the spec

1 similar comment
@JunTaoLuo
Copy link
Contributor

Updated the spec

@JunTaoLuo
Copy link
Contributor

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?

cc @halter73 @Tratcher @davidfowl @loudej @rynowak

@halter73
Copy link
Member

👍 for using object over trying to flow the generic parameter.

@JunTaoLuo
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants