NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.47k forks source link

Making Nancy run on .NET Core #1959

Closed jchannon closed 8 years ago

jchannon commented 9 years ago

Obviously we want to make Nancy run on .NET Core so we'll use this issue as the parent issue.

Please add items to this list or ask @NancyFx/most-valued-minions @NancyFx/owners to append it

andrewcoll commented 9 years ago
andrewcoll commented 9 years ago

I ran Nancy.dll through the portability analyzer, I've uploaded the spreadsheet here:

http://1drv.ms/1G9OAMN

Lists all the references that are not supported in aspnet5 and an alternative in some cases. Most of the System.Type ones are for TinyIOC which we can ignore as there is already a coreclr version of that available.

tugberkugurlu commented 9 years ago

One other thing to consider would be to sit on top of the new routing system rather having a custom one. For example, MVC 6 today hooks into this routing system.

phillip-haydon commented 9 years ago

@tugberkugurlu you mean pass the routes from a module back to the middleware? Or move the routes out of the modules all together and use the middleware to point to routes?

grumpydev commented 9 years ago

We won't be replacing our routing, if people want to use the ASPNet stuff to do mapping that's fine, but that's no different to how we currently use OWIN (and without any of the IApplicationBuilder nonsense - bleh :))

EliotJones commented 9 years ago

I gave a go at cutting down some of the build errors but messed git up a bit in the process: https://github.com/EliotJones/NancyTest/tree/feature/core50 . For me this is building against DNXCore50 with only 200 errors but it might just be my environment, sorry if it's still broken for everyone else

jchannon commented 9 years ago

@awec where's that coreclr version of tinyioc you mention?

janus007 commented 9 years ago

So... does this mean I can use this branch in my DNX 451 project?

jchannon commented 9 years ago

You can try but it's not complete

On Wednesday, 12 August 2015, janus007 notifications@github.com wrote:

So... does this mean I can use this branch in my DNX 451 project?

— Reply to this email directly or view it on GitHub https://github.com/NancyFx/Nancy/issues/1959#issuecomment-130448024.

masaeedu commented 9 years ago

@janus007 I've been using the latest Nancy and Nancy.Owin, along with the UseOwin extension method available in the Microsoft.AspNet.Owin package, and things seem to have been running smoothly so far. I'll re-emphasize that this is DNX 451, i.e. running on the full CLR and probably won't work on CoreCLR. Here's what my Startup class looks like:

using Nancy;
using Nancy.Owin;
using Microsoft.AspNet.Builder;

class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        var nancy = NancyMiddleware.UseNancy(NancyConfiguration);

        // Give Nancy first crack at serving the request
        app.UseOwin(adder => adder.Invoke(nancy));

        // Add any other middleware you want
        app.UseDefaultFiles();
        app.UseStaticFiles();
    }

    private void NancyConfiguration(NancyOptions opts)
    {
        // Configure Nancy however you want
    }
}
khellang commented 9 years ago

@masaeedu You know that we provide an extension method for the AddMiddleware delegate in ASP.NET 5, so you can do

// Either
app.UseOwin(owin => owin.UseNancy(NancyConfiguration));

// Or
app.UseOwin().UseNancy(NancyConfiguration);

And you don't even need Nancy.Owin for it to work. It's in the core package.

masaeedu commented 9 years ago

@khellang Ah, I didn't realize there was a UseNancy for the "MidFunc eater" delegate. Apologies for any misinformation.

tpluscode commented 8 years ago

Hi. I've just created a bare-bone Nancy app in DNX 4.5.1 with a module in a separate class library. It turns out that Nancy cannot discover modules from that library, because the reference is actually not added until some code referenced. The typical way Nancy discovers stuff by inspecting all assemblies in bin also doesn't work, because apparently there is no bin folder, or is there?

Is there any way other than actually referencing some code explicitly? This breaks the feature I liked about Nancy, that I could just drop a dll in bin and it just works.

khellang commented 8 years ago

@tpluscode This is the same for all Nancy projects - DNX or not. Nancy won't scan assemblies not referencing Nancy.dll by default. If you don't reference the dll or not using any Nancy code in your library at compile-time (which makes the compiler strip the reference), it won't be picked up by default. We even added the [assembly: IncludeInNancyAssemblyScanning] attribute just for this scenario.

Also, there's no hardcoded path that Nancy scans. It looks at AppDomain.CurrentDomain.SetupInformation.ApplicationBase and AppDomain.CurrentDomain.SetupInformation.PrivateBinPath, so AFAIK this works on DNX451 as well :smile:

tpluscode commented 8 years ago

@khellang AFAICT [assembly: IncludeInNancyAssemblyScanning] helps when a class library doesn't reference Nancy (or that assembly is removed at compilation) and not when that class library is removed. Is that right?

In my case the Nancy hosted with OWIN in a ASP.NET 5 app doesn't discover my module. ApplicationBase is the DNX path, so that won't help and it turns out that the PrivateBinPath is an empty string. Any ideas?

Also, here's a repro.

khellang commented 8 years ago

Hmm. When I think about it, I doubt anyone's actually tested this scenario. It's probably just been tested with modules in the same assembly as the host. Until we get up and running with DNX's ILibraryManager, I think we'll have to find a workaround here. I think you have to inject IApplicationEnvironment into your Startup and set PrivateBinPath to its ApplicationBasePath or something.

khellang commented 8 years ago

Some context; https://github.com/aspnet/dnx/issues/1253

Alxandr commented 8 years ago

@khellang getting it to run with ILibraryManager should be really easy. Here's the entire MVC's implementation (really few LOCs): https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultAssemblyProvider.cs

khellang commented 8 years ago

Absolutely. But there are some yaks that needs some shaving before we get to that point; We're aiming to empty our PR/issue queue, ship 1.4, then start (continue) on 2.0, which will move to project.json, drop 4.0 etc.

khellang commented 8 years ago

One part of the problem is that Nancy's assembly scanning is static today, while ILibraryManager is instance based, so we have to adjust the assembly scanning a bit. See https://github.com/NancyFx/Nancy/pull/1846 for context.

danfma commented 8 years ago

Hey guys, how is the work on this feature?

khellang commented 8 years ago

@danfma We're working on some stuff to unblock .NET core. net451 etc. should work fine.

danfma commented 8 years ago

Can I help with anything? I don't have much time but I can try to help with something.

khellang commented 8 years ago

The problem is that there's not enough work to do it concurrently. We'll just have to let @thecodejunkie finish #1846 after #2000 is done :smile: Thanks for offering your help! :+1:

danfma commented 8 years ago

Ok!

jchannon commented 8 years ago

UPDATE : I ditched my branch as it got too big and we plan to move to dnx in smaller stages. At time of writing we already have a couple of PRs to change the repo structure and have csproj and project.json side by side in the short term

RTodorov commented 8 years ago

Hi guys,

Is someone still working on this? Can we help somehow?

http://www.ageofascent.com/asp-net-core-exeeds-1-15-million-requests-12-6-gbps/

Looking forward to see Nancy doing it! ;)

Yantrio commented 8 years ago

looks like this issue is a bit old, we just got nancy compiling on the coreclr today (about 3 hours ago) and you can see our efforts over on the coreclr branch (issue #2220 tracked most of the issues)

@jchannon can we close this now?

jchannon commented 8 years ago

This is kind of a duplicate of #2220 so closing but if anyone is following check these out:

https://twitter.com/NancyFx/status/702825092418543616 https://twitter.com/jchannon/status/702835712224325632

RTodorov commented 8 years ago

Wow, that is great!! Nice timing! Are you planing to release a version anytime soon?

jchannon commented 8 years ago

Not at the moment. We plan to do a 2.0-alpha soon from master branch, then once we have all of nancy projects eg/nancy testing, authentication etc compiling I imagine we may do an alpha/beta release of that but this purely guess work at the moment

On 25 February 2016 at 14:45, Renato Quinhoneiro Todorov < notifications@github.com> wrote:

Wow, that is great!! Nice timing! Are you planing to release a version anytime soon?

— Reply to this email directly or view it on GitHub https://github.com/NancyFx/Nancy/issues/1959#issuecomment-188815968.

peterblazejewicz commented 8 years ago

@jchannon What is the status of dotnet core at the moment? I'm trying to port Nancy.Demo.Hosting.Kestrel/Person.cs for RTM on generator-aspnet but I have problems (OS X/ dotent 1.0.0-preview2-003121) Thanks!

jchannon commented 8 years ago

dotnet core is compiling on the master branch, we have no nuget package out yet, we are working on getting our build script over to cake, once that is done we can release a nuget package

On 26 June 2016 at 09:48, Peter Blazejewicz notifications@github.com wrote:

@jchannon https://github.com/jchannon What is the status of dotnet core at the moment? I'm trying to port Nancy.Demo.Hosting.Kestrel/Person.cs for RTM on generator-aspnet but I have problems (OS X/ dotent 1.0.0-preview2-003121) Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NancyFx/Nancy/issues/1959#issuecomment-228590977, or mute the thread https://github.com/notifications/unsubscribe/AAGapvOEMpUda46QSzN2J0mqUtvhvwUtks5qPjzvgaJpZM4E-PLI .

peterblazejewicz commented 8 years ago

Thanks!

a23o commented 8 years ago

Hi guys! How is the cake build going? Do you have a roadmap for the nuget package? I appreciate your hard work.

Thx

cemremengu commented 8 years ago

@a23o already done :) checkout the latest barneyrubble release

a23o commented 8 years ago

Awesome!! Thank you.

mrgrifon commented 8 years ago

Thank you very much for the great work you. I was able to run Nancy under .NET Core But I am having a problems with Nancy.Hosting.Self

Package Nancy.Hosting.Self 2.0.0-barneyrubble is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Nancy.Hosting.Self 2.0.0-barneyrubble supports: net452 (.NETFramework,Version=v4.5.2)

As I can see from sources you already updated this package.

hostingself-updated

I am running .NET Core on Linux Ubuntu 14.04 LTS Could you help me?

phillip-haydon commented 8 years ago

@mrgrifon You should use Kesteral hosting, please refer to https://github.com/NancyFx/Nancy/tree/master/samples/Nancy.Demo.Hosting.Kestrel

erinxocon commented 8 years ago

Will self hosting be implemented for .NET core, or is the plan to just use Kestral?

khellang commented 8 years ago

Kestrel is self-hosting. It's the default model for ASP.NET Core apps. Either using Kestrel, or WebListener.

mmaguigan commented 7 years ago

UseOwin seems to be missing from Kestrel in .NET Core...

khellang commented 7 years ago

UseOwin has never been a part of Kestrel. You need to install Microsoft.AspNetCore.Owin to get the UseOwin extension method.

mmaguigan commented 7 years ago

khellang, it's installed and is no longer present with .NET Core 2.0 preview 1.

EDIT: uhm, okay. I have a project we've been working actively on for the last five months and I upgraded to .NET Core 2.0 preview today and UseOwin was gone... apparently the package was removed in the process. Re-added it back in and all is well. Thanks, sometimes just takes another set of eyes I suppose ;)

reddy6ue commented 6 years ago

Thoroughly confused right now. So, is the netcore 2.0 port happening?

fizxmike commented 6 years ago

The thing I (probably we) love about Nancy.Hosting.Self is the MINIMAL boilerplate... That kestrel demo project is a nightmare for anyone getting started with dotnet core and Nancy IMHO. I don't mind switching to kestrel, just give us a minimalist example PLEASE!?

Right now, OWIN looks like the way to go. There is official documentation for hosting Nancy with OWIN (although no mention of dontenet core). And someone posted usable code snippets on this thread.

fizxmike commented 6 years ago

Nancy on Dotnet Core (OWIN + Kestrel)

Alright! Here is a little gift to anyone who wants to do this but couldn't find a good example. The "key" is to use the clinteastwood preview on the nuget channel (there is also a NancyFX MyGet channel with a bleeding edge build of Nancy.Owin) The catch is that the nancy builds are not for dotnet core, they are .NET framework, but dotnet core 2.0 has some invisible shim to allow imports of .NET Framework dlls, so... YMMV.
(please let me know if anything seems off)

HelloWorld.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <AssemblyName>HelloWorld</AssemblyName>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.2" />
    <PackageReference Include="Nancy" Version="2.0.0-clinteastwood" />
    <PackageReference Include="Nancy.Owin" Version="2.0.0-clinteastwood" />
  </ItemGroup>

</Project>

Program.cs

using System;
using Microsoft.AspNetCore.Hosting;

namespace HelloWorld
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }
}

Startup.cs

using Nancy.Owin;
using Microsoft.AspNetCore.Owin;
using Microsoft.AspNetCore.Builder;

namespace HelloWorld
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseOwin().UseNancy(NancyConfiguration);
        }

        private void NancyConfiguration(NancyOptions opts)
        {
            // Configure Nancy however you want
        }
    }
}

DefaultModule.cs

using Nancy;

namespace HelloWorld
{
     public sealed class DefaultModule : NancyModule
    {
        public Router()
        { 
            Get("/", _ => "Hello (dotnet core) World!");
        }
    }
}