TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
210 stars 53 forks source link

ScaffoldingDesignTimeServices not loaded (duplicate of #31) #36

Closed newsoftinc closed 5 years ago

newsoftinc commented 5 years ago

Running the latest nuget on a new .net core projet.

Running SDK : PM> dotnet --version 2.1.403

Services class :

`using System; using System.IO; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.DependencyInjection;

namespace EFCoreScaffold { public class ScaffoldingDesignTimeServices : IDesignTimeServices { public void ConfigureDesignTimeServices(IServiceCollection services) { // Generate both context and entitites var options = ReverseEngineerOptions.DbContextAndEntities;

        // Register Handlebars helper
        var myHelper = (helperName: "my-helper", helperFunction: (Action<TextWriter, object, object[]>)MyHbsHelper);

        // Add Handlebars scaffolding templates
        services.AddHandlebarsScaffolding(options);

        // Register Handlebars helper
        services.AddHandlebarsHelpers(myHelper);
    }

    // Sample Handlebars helper
    void MyHbsHelper(TextWriter writer, object context, object[] parameters)
    {
        writer.Write("// My Handlebars Helper");
    }
}

} ` Class.hbs (Generated by first run of dotnet ef dbcontext scaffold

`{{> imports}} {{my-helper}} namespace {{namespace}} { {{#if class-annotation}} {{{class-annotation}}} {{/if}}

//This is a test ! public partial class {{class}} {{my-helper}} { {{{> constructor}}} {{> properties}} } } ` The comment //This is a test ! , appears, but the helper is not called.

newsoftinc commented 5 years ago

Hello, I can also confirm that the debugger steps in the ScaffoldingDesignTimeServices by attaching the debugger to dotnet executable. Could you give us a hint ? I need handlebars for my migration from ef6 to core. I can debug the issue. It seems like the helper is not detected / invoked, because debugger never step in the helper function. Where does the helpers get resolved, when the handlebar parser see finds a custom tag?

newsoftinc commented 5 years ago

Ok so your wrapping method, services.AddHandlebarsHelpers(myHelper) , over HandlebarsDotNet.Handlebars.RegisterHelper , does not register the templates in handlebar.

Adding nuget ref to handlebar, and directly add the template, fix the issue. HandlebarsDotNet.Handlebars.RegisterHelper("my-helper", MyHbsHelper);

Why do you make additionnal plumbing over the native call? Only plus I see is to avoid adding references to handlerbar in target projects.

Anyways, i'm not sure where to fix this, but now you know the problem.

tonysneed commented 5 years ago

This appears to be a duplicate of #31, which as been fixed by #42. @newsoftinc Please re-open this issue if this is not the case.

tonysneed commented 5 years ago

@newsoftinc This has been fixed in v1.7.0.