GithubHelp home page GithubHelp logo

hyddan / topshelf.applicationhostbuilder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fresa/topshelf.applicationhostbuilder

0.0 2.0 0.0 1.38 MB

Extension for Topshelf to be able to host any type of application, not just a Console Application

License: MIT License

C# 100.00%

topshelf.applicationhostbuilder's Introduction

Topshelf.ApplicationHostBuilder

Extension for Topshelf to be able to use any type of application, not just a Console Application.

Build status

Build history

Why?

Topshelf requires that you create a project with output type Console Application. This extension removes that requirement. You can use any output type. You can even host your application during unit testing!

Download

https://www.nuget.org/packages/Topshelf.ApplicationHostBuilder/

Release Notes

1.0.1 Incorrect logger for ApplicationHost

Usage

Use the extension method UseApplicationHostBuilder for the host configurator you'll get by initializing the Topshelf HostFactory.

Example

Without command line arguments.

HostFactory.Run(config =>
{
    config.UseApplicationHostBuilder();

    config.Service<MyService>(configurator =>
    {
        configurator.WhenStarted((service, control) => service.Start());
        configurator.WhenStopped(service => service.Stop());
    });
});

With command line arguments.

HostFactory.Run(config =>
{
    using(config.UseApplicationHostBuilder(args))
    {
        config.Service<MyService>(configurator =>
        {
            configurator.WhenStarted((service, control) => service.Start());
            configurator.WhenStopped(service => service.Stop());
        });
    }
});

Caveats

There are some minor caveats.

Test Runners

When using ReSharper's test runner, it will add some arguments when bootstrapping the test assembly. Topshelf parses input arguments by getting them from Environment.GetCommandLineArgs(). It will pick up the arguments from ReSharpers test runner and fail creating the hosting environment. Fortunately they provide a function to override the command line. Use the ApplyCommandLine function on the host configurator supplied by the HostFactory to simulate the behaviour you are testing.

Console Usage

The HelpHost and the TopshelfConsoleTraceListener within Topshelf uses Console's write functions directly, which will not make any sense if you do not have an application that listens to Console's output. Fortunately Console exposes a function (SetOut) making it possible to redirect text being written to Console by rolling your own TextWriter.

Stopping the Application

  • When installing the application as a Windows Service, it works just as described in Topshelf's documentation.
  • When running it through an automated test, you probably want to use the host controller provided by Topshelf after the hosting has started. See WhenStarted function for ServiceConfigurator<T>.
  • When running it from a console/file explorer you need to kill the application from the Task Manager. For now, there is no way to do a graceful stop.
  • When debugging from Visual Studio, just hit Stop Debugging. For now, there is no way to do a graceful stop.

topshelf.applicationhostbuilder's People

Contributors

fresa avatar hyddan avatar

Watchers

James Cloos avatar  avatar

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.