Skip to content

Commit 9ae2b5c

Browse files
committed
Fixed resources, it doesn't seem the Custom Tool Namespace is honoured, and it uses the directory structure instead.
Began work on referencing the embedded partial view by means of some ASPNet Core extension methods to look up razor views among embedded resources (work-in-progress)
1 parent d65f17e commit 9ae2b5c

File tree

10 files changed

+72
-21
lines changed

10 files changed

+72
-21
lines changed

Mvc.JQuery.DataTables.AspNetCore.Example/App_GlobalResources/UserViewResource.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Mvc.JQuery.DataTables.AspNetCore.Example/Controllers/UserTableRowViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
using Mvc.JQuery.DataTables.Example.App_GlobalResources;
22
using Mvc.JQuery.DataTables.Example.Domain;
33
using Mvc.JQuery.DataTables.Models;
4-
using Resources;
4+
using System;
55

66
namespace Mvc.JQuery.DataTables.Example.Controllers
77
{

Mvc.JQuery.DataTables.AspNetCore.Example/Mvc.JQuery.DataTables.AspNetCore.Example.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
1313
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
14-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
15-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
1614
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
1715
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1" />
1816
</ItemGroup>
@@ -23,5 +21,10 @@
2321
<ProjectReference Include="..\Mvc.JQuery.DataTables.AspNetCore\Mvc.JQuery.DataTables.AspNetCore.csproj" />
2422
<ProjectReference Include="..\Mvc.JQuery.DataTables.Common\Mvc.JQuery.DataTables.Common.csproj" />
2523
</ItemGroup>
24+
<ItemGroup>
25+
<EmbeddedResource Update="App_GlobalResources\UserViewResource.resx">
26+
<CustomToolNamespace></CustomToolNamespace>
27+
</EmbeddedResource>
28+
</ItemGroup>
2629

2730
</Project>

Mvc.JQuery.DataTables.AspNetCore.Example/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using Microsoft.AspNetCore.Hosting;
32
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Hosting;
73

84
namespace Mvc.JQuery.DataTables.AspNetCore.Example
95
{

Mvc.JQuery.DataTables.AspNetCore.Example/Startup.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
62
using Microsoft.AspNetCore.Hosting;
73
using Microsoft.Extensions.Configuration;
84
using Microsoft.Extensions.DependencyInjection;
@@ -28,6 +24,7 @@ public Startup(IHostingEnvironment env)
2824
public void ConfigureServices(IServiceCollection services)
2925
{
3026
// Add framework services.
27+
services.AddMvcJQueryDataTables();
3128
services.AddMvc();
3229
}
3330

@@ -49,6 +46,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
4946

5047
app.UseStaticFiles();
5148

49+
app.UseMvcJQueryDataTables();
5250
app.UseMvc(routes =>
5351
{
5452
routes.MapRoute(

Mvc.JQuery.DataTables.AspNetCore.Example/Views/Home/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class SomeController : Controller
8080
<br />
8181

8282
<div>
83-
@if (Request.QueryString["lang"] != "de")
83+
@if (Context.Request.Query["lang"] != "de")
8484
{
8585
<a href="?lang=de#language-switch" id="language-switch">See table with Language settings applied</a>
8686
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.AspNetCore.Mvc.Razor;
2+
using Microsoft.Extensions.FileProviders;
3+
using System;
4+
using System.Reflection;
5+
6+
namespace Microsoft.Extensions.DependencyInjection
7+
{
8+
public static class ConfigureServicesExtensions
9+
{
10+
public static IServiceCollection AddMvcJQueryDataTables(this IServiceCollection services)
11+
{
12+
var dataTablesRazorViewAssembly = typeof(Mvc.JQuery.DataTables.DataTableConfigVm).GetTypeInfo().Assembly;
13+
var settings = new Mvc.JQuery.DataTables.Settings
14+
{
15+
FileProvider = new EmbeddedFileProvider(dataTablesRazorViewAssembly),
16+
};
17+
services.AddSingleton(settings);
18+
services.Configure<RazorViewEngineOptions>(s => s.FileProviders.Add(settings.FileProvider));
19+
return services;
20+
}
21+
}
22+
}
23+
24+
namespace Microsoft.AspNetCore.Builder
25+
{
26+
using Microsoft.Extensions.DependencyInjection;
27+
28+
public static class MvcJQueryDataTablesExtensions
29+
{
30+
public static IApplicationBuilder UseMvcJQueryDataTables(this IApplicationBuilder app)
31+
{
32+
var settings = app.ApplicationServices.GetService<global::Mvc.JQuery.DataTables.Settings>();
33+
if(settings == null)
34+
{
35+
throw new InvalidOperationException("Unable to find the required services. Please add all the required services by calling 'IServiceCollection.{}' inside the call to 'ConfigureServices(...)' in the application startup code.");
36+
}
37+
app.UseStaticFiles(new StaticFileOptions
38+
{
39+
FileProvider = settings.FileProvider,
40+
});
41+
return app;
42+
}
43+
}
44+
}

Mvc.JQuery.DataTables.AspNetCore/Mvc.JQuery.DataTables.AspNetCore.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
12+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
13+
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.0.1" />
1214
</ItemGroup>
1315

1416
<ItemGroup>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Microsoft.Extensions.FileProviders;
2+
3+
namespace Mvc.JQuery.DataTables
4+
{
5+
class Settings
6+
{
7+
public IFileProvider FileProvider { get; set; }
8+
}
9+
}

Mvc.JQuery.DataTables.Common/ResourceHelper.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.Linq;
45
using System.Reflection;
5-
using System.Text;
6-
using System.ComponentModel.DataAnnotations;
76

87
namespace Mvc.JQuery.DataTables
98
{
@@ -13,7 +12,7 @@ public static T GetResourceLookup<T>(Type resourceType, string resourceName)
1312
{
1413
if ((resourceType != null) && (resourceName != null))
1514
{
16-
System.Reflection.PropertyInfo property = resourceType.GetProperty(resourceName, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
15+
PropertyInfo property = resourceType.GetProperty(resourceName, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
1716
if (property == null)
1817
{
1918
return default(T);
@@ -75,4 +74,4 @@ public static object[] EnumValLabPairs(this Type type)
7574
return result.ToArray<object>();
7675
}
7776
}
78-
}
77+
}

0 commit comments

Comments
 (0)