0

I am trying to make a UI middleware and wanted to know what's the recommended way to go about it.

Should I do a AddMVC again in my middleware and give it a custom route or go by embedding resources.

I tried to make a MVC inside my middleware and I am able to hit the controller with the custom route but not the views in my middleware project. The sample website seems to always only look inside the main MVC views folder.

Let me know if you need more information and I will update the question accordingly.

Muqeet Khan
  • 1,894
  • 1
  • 16
  • 26
  • 1
    What would be the issue with having your MVC Views folder? MVC traditionally offers ways to let the views be in a different location. Could this help: http://weblogs.asp.net/imranbaloch/custom-viewengine-aspnet5-mvc6 – janpieter_z Feb 20 '16 at 13:52
  • So that j can use it as a package in another projects ... And not have to build the views again in every project. I think what I am looking at is how to use embedded razor view pages? – Muqeet Khan Feb 20 '16 at 17:43
  • What's a UI middleware? Can you share some code? – Victor Hurdugaci Feb 21 '16 at 08:29
  • Sure. Available at https://github.com/muqeet-khan/SimplyCore ... more specifically https://github.com/muqeet-khan/SimplyCore/blob/master/SimplyCore.TagHelpers/src/SimplyCore.UI/Hosting/SimplyRecorderUIMiddleware.cs#L38 – Muqeet Khan Feb 21 '16 at 22:10

1 Answers1

0

Try to use embed views. You need to add:

"buildOptions": { "embed": [ "Views/**" ] },

Then you should tell mvc to look inside embed files

services
    .AddMvc()
    .AddRazorOptions(
       o =>
       {
         o.FileProviders.Add(new EmbeddedFileProvider(yourAssembly, yourAssembly.GetName().Name));
       }
    );

You alse could try application parts:

AssemblyPart part = new AssemblyPart(yourAssembly);
mvcBuilder.ConfigureApplicationPartManager(manager =>
{
    manager.ApplicationParts.Add(part);
});

foreach (var applicationPart in mvcBuilder.PartManager.ApplicationParts)
{
    var assemblyPart = applicationPart as AssemblyPart;
   if (assemblyPart != null)
   {
       mvcBuilder.AddRazorOptions(options =>
       {
           options.FileProviders.Add(new EmbeddedFileProvider(assemblyPart.Assembly, applicationPart.Name));
       });
   }
}

Hope it helps

Andrei Tserakhau
  • 595
  • 5
  • 12