Closed deepakkumpala closed 6 years ago
Sure, why not 😄
How? I am not finding enough resources. Basically I am using .net core 2.1 and .net standard for all the libraries in my project. I want to install it as windows service and host pages at localhost for browsing. Basically trying to achieve below result using Nancy
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1
I can not use TopShelf as Topshelf current version is not supported by .net core 2.0 applications.
Have you tried going through the guide? Try after you've set it up as a Windows service, it's just a matter of hooking Nancy up in your Startup class. Look at the Kestrel sample in this repo to see how it's done.
I have already seen Kestrel sample but it can not be hosted as windows service. I do not see "Start" and "Stop" methods or service manager class to override my functionalities.
Which guide you are referring to? kindly provide the link to exact requirement.
Thank you. so if I understand currently, once I create windows service using .net core then we need to hook up Nancy. I have added Nancy.Hosting.Self nuget package , but I am getting below warning
Package 'Nancy.Hosting.Self 1.4.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.
Then I tried below
Install-Package Nancy -Pre
which resolved the warning, but I am not able to get app.UseNancy() under Configure startup.
Then I tried adding nuget Microsoft.AspNetCore.Owin
This I am able to write code as below
app.UseOwin(x => x.UseNancy());
But my question now is, Is it right way? Am I in right path?
I am new bee to development. Is there any sample which shows hooking up Nancy to .net core 2.1 windows service?
Is there any sample which shows hooking up Nancy to .net core 2.1 windows service?
No, but as I mentioned, you need to combine two resources:
The first will show you how to host ASP.NET Core in a Windows service, the second will show you how to hook up Nancy in your Startup class.
Nancy.Hosting.Self
is .NET Framework only (not .NET Core). In addition to the core Nancy
package, you need to install the following packages:
Adding Nancy to your pipeline is done like this:
Thank you. we can close this ticket. Appreciated. I have updated my previous question. Great. Thanks
Awesome! Feel free to keep asking if you encounter problems 😄
I would like reopen this ticket as I am stuck in integrating Autofac to the above solution. The reason I need Autofac is my existing class libraries have dependency on Autofac.
Now, How do I integrate Autofac to Nancy ?
You should be able to use https://github.com/NancyFx/Nancy.Bootstrappers.Autofac
Thank you. Appreciated support.
I have added prerelease version
Install-Package Nancy.Bootstrappers.Autofac -Version 2.0.0-clinteastwood
I have managed to build the application without build errors from below code but unable to get the instances. Basically how do I inject?
protected override void ConfigureApplicationContainer(ILifetimeScope container)
{
_services.Configure<Settings>(_configuration.GetSection("MySettings"));
var deviceId = _configuration["Settings:DeviceId"];
var containerFactory = new ContainerFactory();
container.Update(builder =>
{
builder.RegisterInstance(containerFactory).As<IContainerFactory>();
containerBuilder.Register(c => new Engine(containerFactory));
containerBuilder.Register(i => new HubClient(deviceId, containerFactory)).As<HubClient> ().SingleInstance();
});
base.ConfigureApplicationContainer(container);
}
But now how to I inject it in my modules?
public static void Main(string[] args)
{
var isService = !(Debugger.IsAttached || args.Contains("--console"));
var builder = CreateWebHostBuilder(args.Where(arg => arg != "--console").ToArray());
if (isService)
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
builder.UseContentRoot(pathToContentRoot);
}
var host = builder.Build();
if (isService)
{
IMyInterface Engine = host.Services.GetService<IMyInterface>();// this line fails.
host.RunAsCustomService();
}
else
{
host.Run();
}
}
Note: Engine class is dependent on 'DeviceId' and 'containerFactory' parameter
I am very close to solution! Hope you help me reach it!
I have created a question in stack overflow https://stackoverflow.com/questions/51988982/how-do-i-integrate-nancy-with-autofac-and-asp-net-core-windows-service
Can I host windows service using Nancy without .net framework? I want to use .net core.
Prerequisites
DEBUG
andRELEASE
modeDescription
Steps to Reproduce
System Configuration