GithubHelp home page GithubHelp logo

rebus-org / topper Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 3.0 2.75 MB

:tophat: Simple Windows Service helper (Topshelf-based, Azure Web Job capable)

License: Other

C# 91.26% Batchfile 8.74%
windows-service windows-services topshelf hosting windows

topper's Introduction

Topper

install from nuget

Generic Windows service host - makes an ordinary Console Application hostable in the following scenarios:

  • To be F5-debugged locally - on your developer machine
  • To be installed as a Windows Service - on the servers in your basement
  • To be executed as an Azure Web Job - in the cloud!!

Based on Topshelf. Exposes a drastically simplified API, where "services" are simply factories that return something IDisposable.

Targets .NET Standard 2.0, so you must target either netcoreapp2.0 (or later), or net462 (or later) in your Console Application.

Getting started

Create YourNewAwesomeWindowsService as a Console Application project targeting AT LEAST .NET 4.6.2 or .NET Core App 2.0.

Include the NuGet package ๐Ÿ“ฆ

Install-Package Topper -ProjectName YourNewAwesomeWindowsService

and clean up your Program.cs so it becomes nice like this: ๐ŸŒป

namespace YourNewAwesomeWindowsService
{
    class Program
    {
        static void Main()
        {
                
        }
    }
}

and then you configure Topper by going

var configuration = new ServiceConfiguration()
	.Add(.. function that returns an IDisposable ..)
	.Add(.. another function that returns an IDisposable ..);

ServiceHost.Run(configuration);

in Main, which could look like this:

namespace YourNewAwesomeWindowsService
{
    class Program
    {
        static void Main()
        {
            var configuration = new ServiceConfiguration()
                .Add(() => new MyNewAwesomeService());

            ServiceHost.Run(configuration);                
        }
    }
}

๐Ÿต Easy!

Topper uses LibLog โšก to log things. If you want to use Serilog, you probably want to

Install-Package Serilog.Sinks.ColoredConsole -ProjectName YourNewAwesomeWindowsService

and configure the global ๐ŸŒ logger before starting your service:

namespace YourNewAwesomeWindowsService
{
    class Program
    {
        static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            var configuration = new ServiceConfiguration()
                .Add(() => new MyNewAwesomeService());

            ServiceHost.Run(configuration);                
        }
    }
}

And that is how you use Topper.

How to run locally?

Press F5 or CTRL+F5 in Visual Studio.

Run the .exe

How to run as Windows Service?

Open an elevated command prompt, and run the .exe with the install argument, like so:

C:\apps\YourApp> YourApp.exe install

and then some Windows Service Control ๐Ÿšฅ stuff will appear and tell you some details on how it was installed.

You can remove it again like this:

C:\apps\YourApp> YourApp.exe uninstall

Not exactly surprising. ๐Ÿ‘

How to run as Azure Web Job?

Just run it as you would any other Console Application as a Continuous Web Job.

Topper automatically monitors for the presence of the WEBJOBS_SHUTDOWN_FILE, to be able to shut down gracefully and dispose your IDisposables. โ™ป๏ธ


topper's People

Contributors

igitur avatar mookid8000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

topper's Issues

Switch to LibLog for logging abstraction

I'd love to use this library, but I don't want to use Serilog. Would you accept a PR converting it to use LibLog instead? That way users could have their pick of a few popular solutions including Serilog.

Expose underlying Topshelf ServiceConfigurator

Hi,

Firstly, thanks for this project and the whole Rebus suite.

I'd like to have more control over my Topshelf installation. And for that I need to get the underlying ServiceConfigurator instance through Topper.

I can submit a PR to do this, but would like to check the exact API with you first and whether you're OK with the concept in the first place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.