davidfowl / signalr-ports

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Move golang implementation to a new repository

davidfowl opened this issue · comments

Lets do this after #8

I added all changes to and started adding the transient hub and scoped HubContext.Items. I also changed passing the hub to server into passing a newHub func which will be called on any hub method invocation. If someone uses an DI framework which is able to supply a initialized hub instance (not all go DI frameworks have this feature), newHub can call the DI framework.

Is this even a common pattern in go frameworks? Are there any examples? I don’t want to introduce that concept into signalr if it isn’t but maybe a factory is enough to make it all work.

Frameworks are no common pattern in go :-)
google/wire has so called injectors which return initialized objects and might be the most commonly used DI package. Factory methods like newHub() are a common pattern in go

OK lets go the factory route, it's simple and does the job. This should be an options object

func NewServer(hub HubInterface) *Server {
. We're going to need to allow configuring a bunch of things anyways.

Also here

func MapHub(mux *http.ServeMux, path string, hub HubInterface) {

Unfortunately go doesn't have overloads so we'll need 2 methods 😄 (for convenience)

non transient hubs can be emulated wth a newHub func like this:
myChat := &chat{}
s := signalr.NewServer(func() signalr.HubInterface {return myChat})

Yea but that’s syntactically noisy. Simple things should be simple.

https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis seems an elegant solutions to me.
I did some experiments here: 0ca2529

@davidfowl https://github.com/philippseith/signalr is now a separate repository. BDD test coverage is good, documentation, lint/vet/etc is quite good. Close this issue?

@philippseith I'd actually like to own the repository as discussed on your original PR (as I planned to continue working on it). I don't mind giving you commit access...

@davidfowl I appreciate to work with you on this project and bring my changes into the new repo. When are you planning to create it?

Thanks @philippseith I'll create it tomorrow.

@philippseith can you send the PR with the options

? new repo?