Skip to content

Commit

Permalink
#3 Added Sample.Web.Module, Fixed DefaultEmbeddedResourceProvider and…
Browse files Browse the repository at this point in the history
… CoreControllerBase
  • Loading branch information
Lukas Gerbenis committed Oct 1, 2015
1 parent bd7ce54 commit 7be5eba
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BetterModules.Core.Web.Security;
using BetterModules.Core.Web.Web;
using BetterModules.Core.Web.Web.EmbeddedResources;
using Microsoft.AspNet.Mvc.Razor;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
Expand Down Expand Up @@ -64,6 +65,10 @@ private static void LoadWebAssemblies(this IServiceCollection services)
var resourceProvider = ActivatorUtilities.CreateInstance<DefaultEmbeddedResourceProvider>(provider);
resourceProvider.LoadEmbeddedResourcesFrom(modulesRegistration.GetModules());
services.AddInstance<IEmbeddedResourceProvider>(resourceProvider);
services.Configure<RazorViewEngineOptions>(opt =>
{
opt.FileProvider = resourceProvider;
});
}
}
}
9 changes: 2 additions & 7 deletions vNext/src/BetterModules.Core.Web/Mvc/CoreControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ protected CoreControllerBase()
/// <value>
/// The current command principal.
/// </value>
IPrincipal ICommandContext.Principal
{
get
{
return User;
}
}
IPrincipal ICommandContext.Principal => User;

[FromServices]
public virtual ICommandResolver CommandResolver { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Text;
using BetterModules.Core.Modules.Registration;
using BetterModules.Core.Web.Modules;
using Microsoft.AspNet.FileProviders;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching;
Expand Down Expand Up @@ -50,21 +51,26 @@ public void LoadEmbeddedResourcesFrom(IEnumerable<ModuleRegistrationContext> mod
{
foreach (var module in modules)
{
var assembly = Assembly.Load(module.ModuleDescriptor.AssemblyName);
var resourceNames = assembly.GetManifestResourceNames();

foreach (var resourceName in resourceNames)
var descriptor = module.ModuleDescriptor as WebModuleDescriptor;
if (descriptor != null)
{

var subpathIndex = resourceName.IndexOf('.') + 1;
var extensionIndex = resourceName.LastIndexOf('.');
var builder = new StringBuilder($"Areas/{module.ModuleDescriptor.Name}/{resourceName.Substring(subpathIndex)}");
builder.Replace("/", ".");
builder.Remove(extensionIndex, 1);
builder.Insert(extensionIndex, ".");
var path = builder.ToString();
var fileInfo = new EmbeddedResourceInfo(assembly, resourceName, Path.GetFileName(resourceName), lastModified);
embeddedFileInfoCache.TryAdd(path, fileInfo);
var assembly = Assembly.Load(descriptor.AssemblyName);
var resourceNames = assembly.GetManifestResourceNames();
var assemblyName = descriptor.AssemblyName.Name + ".";

foreach (var resourceName in resourceNames)
{
var builder =
new StringBuilder($"Areas/{descriptor.AreaName}/{resourceName.Replace(assemblyName, "")}");
builder.Replace(".", "/");
var extensionIndex = builder.ToString().LastIndexOf('/');
builder.Remove(extensionIndex, 1);
builder.Insert(extensionIndex, ".");
var path = builder.ToString();
var fileInfo = new EmbeddedResourceInfo(assembly, resourceName, Path.GetFileName(resourceName),
lastModified);
embeddedFileInfoCache.TryAdd(path, fileInfo);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BetterModules.Core.DataAccess.DataContext.Migrations;
using BetterModules.Core.Environment.Assemblies;
using BetterModules.Core.Environment.FileSystem;
using BetterModules.Core.Infrastructure.Commands;
using BetterModules.Core.Modules.Registration;
using BetterModules.Core.Security;
using Microsoft.Framework.Configuration;
Expand Down Expand Up @@ -53,6 +54,7 @@ public static void ConfigureDefaultServices(this IServiceCollection services)
services.AddSingleton<IVersionChecker, DefaultVersionChecker>();
services.AddSingleton<IMigrationRunner, DefaultMigrationRunner>();

services.AddScoped<ICommandResolver, DefaultCommandResolver>();
services.AddScoped<IUnitOfWork, DefaultUnitOfWork>();
services.AddScoped<IRepository, DefaultRepository>();
}
Expand Down
5 changes: 5 additions & 0 deletions vNext/src/BetterModules.Mvc6.Sandbox/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseErrorHandler("/Home/Error");
}

app.UseBetterStaticFiles();

// Add static files to the request pipeline.
app.UseStaticFiles();

// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areasDefault",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
Expand Down
3 changes: 2 additions & 1 deletion vNext/src/BetterModules.Mvc6.Sandbox/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"Microsoft.Framework.Logging.EventLog": "1.0.0-beta7",
"Microsoft.Framework.Logging.Console": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Xml": "1.0.0-beta7",
"BetterModules.Core.Web": "1.0.0-*"
"BetterModules.Core.Web": "1.0.0-*",
"BetterModules.Sample.Web.Module": "1.0.0-*"
},

"commands": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq;
using BetterModules.Core.Infrastructure.Commands;
using BetterModules.Core.Modules.Registration;
using BetterModules.Core.Web.Modules;
using BetterModules.Core.Web.Mvc.Commands;
using BetterModules.Sample.Web.Module.Models;

namespace BetterModules.Sample.Web.Module.Commands.GetModulesList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System.Web.Mvc;
using BetterModules.Core.Web.Mvc;
using BetterModules.Core.Web.Mvc;
using BetterModules.Sample.Web.Module.Commands.GetModulesList;
using Microsoft.AspNet.Mvc;

namespace BetterModules.Sample.Web.Module.Controllers
{
[Area("module-bettermoduleswebsample")]
public class SampleWebController : CoreControllerBase
{
public ActionResult Index()
public IActionResult Index()
{
return Content("Hello World From Sample Controller!");
}

public ActionResult Test()
public IActionResult Test()
{
return View();
}

public ActionResult ModulesList()
public IActionResult ModulesList()
{
var command = GetCommand<GetModulesListCommand>();
var model = command.Execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ namespace BetterModules.Sample.Web.Module
{
public class SampleWebModuleDescriptor : WebModuleDescriptor
{
public override string Description
{
get
{
return "Sample BetterModules Web Module";
}
}
public override string Description => "Sample BetterModules Web Module";

public override string Name
{
get
{
return "BetterModulesWebSample";
}
}
public override string Name => "BetterModulesWebSample";
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7be5eba

Please sign in to comment.