What is the correct way to embed wyam into an asp net core mvc solution

Introduction

When it comes to developing web applications, ASP.NET is a popular choice developers. It provides a robust framework for dynamic and scalable websites. One common question that arises is how to embed Wyam into an ASP.NET Core MVC solution. In this article, we will explore the way to achieve this integration.

What is Wyam?

Wyam is a static content generator that allows you to generate static websites or documentation from various sources. It provides a flexible and extensible pipeline-based approach to content generation. Integrating Wyam into an ASP.NET Core MVC solution can be beneficial when you need to generate static content alongside your dynamic web application.

Step 1: Install Wyam

The step is to install Wyam as a NuGet package in your ASP.NET Core MVC solution. Open the Package Manager Console and run the following :

Install-Package Wyam

Step 2: Configure Wyam

After Wyam, you need to configure it to generate the desired static content. Create a new class file, for example, “WyamConfig.cs”, and add the following code:

using Wyam.Common.Configuration;
using Wyam.Common.Execution;
using Wyam.Core.Configuration;
using Wyam.Core.Execution;

public class WyamConfig : IRecipe
{
    public void Apply(IEngine engine)
    {
        engine.Pipelines.Add("Content",
            ReadFiles("input/**/*.md"),
            Markdown(),
            WriteFiles("output")
        );
    }
}

In this example, we define a pipeline named “Content” that reads Markdown files from the “input” folder, them using the Markdown module, and writes the output to the “output” folder. You can this configuration based on your specific requirements.

Step 3: Integrate Wyam into ASP.NET Core MVC

To integrate Wyam into your ASP.NET Core MVC solution, you need to add a middleware that triggers the Wyam generation process. Open the “Startup.cs” file and add the following code to the “Configure” method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    // Other middleware configurations

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
        app.UseHsts();
    }

    // Wyam middleware
    app.UseWyam();

    // Other middleware configurations
}

By adding the “app.UseWyam()” line, you enable the Wyam middleware in your ASP.NET Core MVC application. This middleware will generate the static content based on the Wyam configuration defined in the step.

Step 4: and Run

Now that you have integrated Wyam into your ASP.NET Core MVC solution, you can build and run your application. Wyam will generate the static content based on the configured pipeline whenever the application is executed.

Conclusion

Embedding Wyam into an ASP.NET Core MVC solution allows you to generate static content alongside your dynamic web application. By following the steps outlined in this article, you can seamlessly integrate Wyam and leverage its powerful static content generation capabilities. Whether you need to generate documentation or create static websites, Wyam can be a valuable addition to your ASP.NET Core MVC development workflow.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents