topshelf update: service locator

31 views
Skip to first unread message

Dru Sellers

unread,
Nov 27, 2009, 9:28:40 AM11/27/09
to masstrans...@googlegroups.com
The service locator code is going to be going away. During the reorg it occured to me that I am only using one function of the whole interface and so I am replacing it with a simple

Func<string, object> which will have a name too. This way you can use a container if you want or not, and the code doesn't have to care. just tell me how to get it.

The string that is passed in is the name of the service, in case you want to look things up by name.

Example:

                x.ConfigureServiceInIsolation<TownCrier>("tc", s =>
                {
                    s.HowToBuildService(name=> new TownCrier());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });



-d

Chris Patterson

unread,
Nov 27, 2009, 10:31:56 AM11/27/09
to masstrans...@googlegroups.com
Why not use?

public void HowToBuildService(Func<TService> getService)
{
}

The service is already typed by the ConfigureServiceInIsolation, so you can use that TService to type instead of degrading to object.




--

You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

Chris Patterson



Dru Sellers

unread,
Nov 27, 2009, 10:41:30 AM11/27/09
to masstrans...@googlegroups.com
Using Func<string, object>

the string for backwards if anyone wants it. its not hard to add.
object because I don't have access to the type the whole way through.   yet.

-d

Travis Smith

unread,
Nov 27, 2009, 11:06:50 AM11/27/09
to masstrans...@googlegroups.com
"the string for backwards if anyone wants it."

For backwards compatibility?

Dru Sellers

unread,
Nov 27, 2009, 11:29:05 AM11/27/09
to masstrans...@googlegroups.com
currently we pull the service out by name from the container.
if you needed to continue to do that this would be the way to do it.
-d

KevM

unread,
Dec 3, 2009, 11:14:36 AM12/3/09
to masstransit-discuss
Pulling the service by name kinda of messes things up for people that
don't name types registrations with the container. However, providing
the HowToBuildService override giving me the ability to push an action
in that maps to my container usage is a nice way to defeat that caked
on baked on usage of the container. I do have to say though that the
ServiceBuilder type is confusing when encountered. I was expecting it
to be a Func<TService>

-Kevin Miller

On Nov 27, 10:29 am, Dru Sellers <d...@drusellers.com> wrote:
> currently we pull the service out by name from the container.
> if you needed to continue to do that this would be the way to do it.
> -d
>
> On Fri, Nov 27, 2009 at 10:06 AM, Travis Smith <tra...@legomaster.net>wrote:
>
>
>
> > "the string for backwards if anyone wants it."
>
> > For backwards compatibility?
>
> > On Fri, Nov 27, 2009 at 10:41 AM, Dru Sellers <d...@drusellers.com> wrote:
> > > Using Func<string, object>
>
> > > the string for backwards if anyone wants it. its not hard to add.
> > > object because I don't have access to the type the whole way through.
> > yet.
>
> > > -d
>
> > > On Fri, Nov 27, 2009 at 9:31 AM, Chris Patterson <
> > chrisfromtu...@gmail.com>
> > >> masstransit-dis...@googlegroups.com<masstransit-discuss%2Bunsu bsc...@googlegroups.com>
> > .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/masstransit-discuss?hl=en.
>
> > >> Chris Patterson
> > >> chrisfromtu...@gmail.com
>
> > >> --
>
> > >> You received this message because you are subscribed to the Google
> > Groups
> > >> "masstransit-discuss" group.
> > >> To post to this group, send email to
> > masstrans...@googlegroups.com.
> > >> To unsubscribe from this group, send email to
> > >> masstransit-dis...@googlegroups.com<masstransit-discuss%2Bunsu bsc...@googlegroups.com>
> > .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/masstransit-discuss?hl=en.
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups
> > > "masstransit-discuss" group.
> > > To post to this group, send email to
> > masstrans...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > masstransit-dis...@googlegroups.com<masstransit-discuss%2Bunsu bsc...@googlegroups.com>
> > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/masstransit-discuss?hl=en.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "masstransit-discuss" group.
> > To post to this group, send email to masstrans...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > masstransit-dis...@googlegroups.com<masstransit-discuss%2Bunsu bsc...@googlegroups.com>
> > .

Dru Sellers

unread,
Dec 3, 2009, 12:47:35 PM12/3/09
to masstrans...@googlegroups.com
#1 - ok, I will make the name optional


" I do have to say though that the
ServiceBuilder type is confusing when encountered. I was expecting it
to be a Func<TService>"

good feedback

I made it a type so that I can track it internally a bit easier, but I will look at making it into a Func<TService>

-d

To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com.

Chris Patterson

unread,
Dec 3, 2009, 6:52:16 PM12/3/09
to masstrans...@googlegroups.com
that's what I've been pushing for too, a simple Func<TService> and how it gets created is really no concern of TS.

To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.



Chris Patterson



Dru Sellers

unread,
Dec 4, 2009, 8:51:33 AM12/4/09
to masstrans...@googlegroups.com
It is a Func<string, TService> already. don't get your britches in a bunch.
-d

Dru Sellers

unread,
Dec 4, 2009, 8:55:17 AM12/4/09
to masstrans...@googlegroups.com
ok. it is no longer dependent on name.
-d

Kevin Miller

unread,
Dec 4, 2009, 11:50:21 AM12/4/09
to masstrans...@googlegroups.com
Excellent! Did you commit that? I'll give it a go.

Kevin Miller

Dru Sellers

unread,
Dec 4, 2009, 11:56:27 AM12/4/09
to masstrans...@googlegroups.com
It's been that way since the de iservicelocator atuff

-d

Kevin Miller

unread,
Dec 4, 2009, 12:02:59 PM12/4/09
to masstrans...@googlegroups.com
Ah I see the ConfigureService sans string method there but unfortunately it is not exposed to the IRunnerConfigurator interface so it is not exposed to the DSL. 

Also I think I found a bug in that if I configure more than one service with the same name the ServiceCoordinator blows up when adding the ServiceController to a dictionary that is keyed by that name. 

I can look at writing you a red test once I get things battened down.

Kevin Miller

Dru Sellers

unread,
Dec 4, 2009, 2:49:45 PM12/4/09
to masstrans...@googlegroups.com
ah! ok.

Dru Sellers

unread,
Dec 4, 2009, 2:54:40 PM12/4/09
to masstrans...@googlegroups.com
huh? not exposed to the dsl?
-d

Dru Sellers

unread,
Dec 4, 2009, 2:55:18 PM12/4/09
to masstrans...@googlegroups.com
you still have to name the service.
if you don't give me a unique name, how should I identify them?

-d

Kevin Miller

unread,
Dec 4, 2009, 3:13:30 PM12/4/09
to masstrans...@googlegroups.com
Naming the service seems to me a concern of Topshelf and not the user. I am not sure what value having an identifier gives me the user. 

Right now to get around this limitation I am just concatenating a GUID onto the type name.

DSL: 

The IRunnerConfigurator does not have the RunnerConfigurator.ConfigureService<TService>() method exposed to it. 

This does not compile:

var cfg = RunnerConfigurator.New(config => config.ConfigureService<IMyService>());

Kevin Miller

Dru Sellers

unread,
Dec 4, 2009, 3:37:45 PM12/4/09
to masstrans...@googlegroups.com
the name would be used for commands later to start/stop individual services.

-d

Dru Sellers

unread,
Dec 4, 2009, 3:39:25 PM12/4/09
to masstrans...@googlegroups.com
var cfg = RunnerConfigurator.New(config => config.ConfigureService<
IMyService>());

ok. I must be dense.

you have to supply a name and a configuration block. so why would that work?
If it was added what would it do?
-d


On Fri, Dec 4, 2009 at 2:13 PM, Kevin Miller <scou...@gmail.com> wrote:

Kevin Miller

unread,
Dec 4, 2009, 3:54:23 PM12/4/09
to masstrans...@googlegroups.com

Kevin Miller

Kevin Miller

unread,
Dec 4, 2009, 3:57:03 PM12/4/09
to masstrans...@googlegroups.com
For myself... I don't really have a need to stop the service during the lifecycle. But if I did it feels like foisting the requirement of uniquely identifying each service onto the user is draconian. I would also argue that a string is not a great identifier due to potential collisions. It seems like you could give me a handle to a service commander. On which I could later call Stop() and/or Start() if I so desired. Something like:

var serviceHandle = configurator.ConfigureService<IMyService>(service => ...config...);

Down the road I could call serviceHandle.Stop() or Pause() or Continue() if so desired. 

If you wanted a human readable description for the service make that an optional part of the config DSL. : config.ServiceDescription = "Rules Engine Service";

Want to have a phone conversation about this? It feels like email may be failing us. In general I am good to go. I have my TypeName+GUID workaround. I would be happy to bang out a patch around my suggestion. I owe you guys.

Kevin Miller 

Dru Sellers

unread,
Dec 4, 2009, 4:17:23 PM12/4/09
to masstrans...@googlegroups.com
yeah lets do a phone call sometime.

Kevin Miller

unread,
Dec 4, 2009, 6:20:41 PM12/4/09
to masstrans...@googlegroups.com
For people on the list: 

I spoke with Dru and Chris about this thread. We decided to expose a ConfigureService that does not require a name to the DSL effectively making the service name optional. Dru was going to use my typename + Guid when auto selecting a service name to work around potential name collisions if the same service type is used multiple times. 

They also filled me in on some cool stuff being worked on to make configuring isolated services easy and reloadable. Good stuff to look forward to.

Kevin Miller

Dru Sellers

unread,
Dec 7, 2009, 7:29:59 PM12/7/09
to masstrans...@googlegroups.com
ok. think this is in.
rev 128
-d
Reply all
Reply to author
Forward
0 new messages