I recently discovered TopShelf. From everything I have read, it looks very cool. The only problem is that I have not been able to use it. I have to have missed something. Below is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace TestTopShelf {
public class FooBar {
public FooBar() {
}
public void Start() { }
public void Stop() { }
}
public class Program {
public static void Main() {
HostFactory.Run(x => {
x.Service<FooBar>( s => {
});
});
}
}
}
You can see that it is a bit incomplete. When I am trying to set properties of the 's' object for ConstructUsing, WhenStarted, and WhenStopped Visual Studio is not inferring the correct type. I am new to lambda expressions and even newer to TopShelf, so I am not sure what I am doing.
I am using this page in the TopShelf documentation to get me started. It looks pretty straight forward, so I am not sure what I have missed.
updated code
using Autofac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace KeithLink.Svc.Windows.OrderService2 {
class FooBar {
public FooBar() { }
public void Start() { }
public void Stop() { }
}
class Program {
static void Main(string[] args) {
HostFactory.Run(x => {
x.Service<FooBar>(s => {
s.ConstructUsing(name => new OrderService());
s.WhenStarted(os => os.Start());
s.WhenStopped(os => os.Stop());
});
x.RunAsLocalSystem();
x.SetDescription("some service description");
x.SetServiceName("ServiceName");
x.SetDisplayName("Service Display Name");
});
}
}
}