简体   繁体   中英

c# Console App With Web API In vNext

i have a console application that contains a number of events that i want to hook into. I want to build it into a microservice and have an umber of smaller console based applications that run continuously with an API that can configure the application or retrieve data. I have the Web API and application completely written. However im stuck in marrying the two together, i did think about doing it the Dependency Injection way with .AddTransient however i cant seem to add events to it.

does anyone know of a way in which i can have my console application running continuously (its a DHCP service) and then re-configure it via an API and for it to update the application from the API controller.

everything is written in vNEXT using .NET Core.

Any help/pointers would be very much appreciated!

Make sure the console applications are created from the "Console Application (Package)" template. Add project references from the Web API to these console application projects. In the ConfigureServices of the Startup class of the Web API project you van add the class (which has the events) to the services collection (be careful with Transient though). I've worked out an example: https://github.com/DannyvanderKraan/InjectDependencyWithEvents

Does this help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM