* Using RazorView<dynamic> as base type until we get model support

* Modifying ViewData to share inner dictionary until we figure out how to
  pass it correctly
* Removing unused NuGet.config
This commit is contained in:
Pranav K 2014-01-30 07:26:46 -08:00
parent 85a25685d2
commit 6c9d562fc3
10 changed files with 50 additions and 37 deletions

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
<packageSourceCredentials>
<AspNetVNext>
<add key="Username" value="aspnetreadonly" />
<add key="ClearTextPassword" value="4d8a2d9c-7b80-4162-9978-47e918c9658c" />
</AspNetVNext>
</packageSourceCredentials>
</configuration>

View File

@ -17,16 +17,12 @@ namespace MvcSample
var serviceProvider = MvcServices.Create(); var serviceProvider = MvcServices.Create();
// HACK to determine app root. // HACK appbase doesn't seem to work. When in VS we're pointing at bin\Debug\Net45, so move up 3 directories
string appRoot = Environment.CurrentDirectory; string appRoot = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", ".."));
while (!String.IsNullOrEmpty(appRoot) && !appRoot.TrimEnd(Path.DirectorySeparatorChar).EndsWith("MvcSample"))
{
appRoot = Path.GetDirectoryName(appRoot);
}
serviceProvider.AddInstance<IFileSystem>(new PhysicalFileSystem(appRoot)); serviceProvider.AddInstance<IFileSystem>(new PhysicalFileSystem(appRoot));
serviceProvider.Add<IVirtualFileSystem, VirtualFileSystem>(); serviceProvider.Add<IVirtualFileSystem, VirtualFileSystem>();
serviceProvider.Add<IMvcRazorHost, MvcRazorHost>(); serviceProvider.AddInstance<IMvcRazorHost>(new MvcRazorHost("Microsoft.AspNet.Mvc.Razor.RazorView<dynamic>"));
serviceProvider.Add<ICompilationService, CscBasedCompilationService>(); serviceProvider.Add<ICompilationService, CscBasedCompilationService>();
serviceProvider.Add<IRazorCompilationService, RazorCompilationService>(); serviceProvider.Add<IRazorCompilationService, RazorCompilationService>();
serviceProvider.Add<IVirtualPathViewFactory, VirtualPathViewFactory>(); serviceProvider.Add<IVirtualPathViewFactory, VirtualPathViewFactory>();

View File

@ -1,4 +1,4 @@
@model MvcSample.User 
@{ @{
Layout = "~/Views/Shared/_Layout.cshtml"; Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Home Page"; ViewBag.Title = "Home Page";
@ -11,7 +11,7 @@
</div> </div>
<div class="row"> <div class="row">
<h3>Hello @Model.Name!</h3> <h3>Hello!</h3>
<div class="col-md-4"> <div class="col-md-4">
<h2>Getting started</h2> <h2>Getting started</h2>
<p> <p>

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Razor
string outFile = Path.Combine(_tempDir, Path.GetRandomFileName() + ".dll"); string outFile = Path.Combine(_tempDir, Path.GetRandomFileName() + ".dll");
StringBuilder args = new StringBuilder("/target:library "); StringBuilder args = new StringBuilder("/target:library ");
args.AppendFormat("/out:\"{0}\" ", outFile); args.AppendFormat("/out:\"{0}\" ", outFile);
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll")) foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll"))
{ {
args.AppendFormat("/R:\"{0}\" ", file); args.AppendFormat("/R:\"{0}\" ", file);
} }
@ -37,8 +37,18 @@ namespace Microsoft.AspNet.Mvc.Razor
var outputStream = new MemoryStream(); var outputStream = new MemoryStream();
// common execute // common execute
var process = CreateProcess(args.ToString()); Process process = CreateProcess(args.ToString());
int exitCode = await Start(process, outputStream); int exitCode;
try
{
File.WriteAllText(inFile, contents);
exitCode = await Start(process, outputStream);
}
finally
{
File.Delete(inFile);
}
string output = GetString(outputStream); string output = GetString(outputStream);
if (exitCode != 0) if (exitCode != 0)

View File

@ -4,8 +4,8 @@ using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.DependencyInjection;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
var viewData = context.ViewData as ViewData<TModel>; var viewData = context.ViewData as ViewData<TModel>;
ViewData = viewData ?? new ViewData<TModel>(context.ViewData); ViewData = viewData ?? new ViewData<TModel>(context.ViewData);
Model = (TModel)ViewData.Model; Model = ViewData.Model;
InitHelpers(context); InitHelpers(context);
return base.RenderAsync(context, writer); return base.RenderAsync(context, writer);

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using Microsoft.Owin.FileSystems; using Microsoft.Owin.FileSystems;
@ -21,6 +20,7 @@ namespace Microsoft.AspNet.Mvc.Razor
if (_fileSystem.TryGetFileInfo(translated, out fileInfo)) if (_fileSystem.TryGetFileInfo(translated, out fileInfo))
{ {
fileInfo = new VirtualFile(subpath, fileInfo); fileInfo = new VirtualFile(subpath, fileInfo);
return true;
} }
return false; return false;
} }
@ -31,6 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor
if (_fileSystem.TryGetDirectoryContents(translated, out contents)) if (_fileSystem.TryGetDirectoryContents(translated, out contents))
{ {
contents = contents.Select(c => new VirtualFile(subpath + '/' + c.Name, c)); contents = contents.Select(c => new VirtualFile(subpath + '/' + c.Name, c));
return true;
} }
return false; return false;
} }

View File

@ -1,16 +1,15 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Razor;
using Microsoft.Owin.FileSystems; using Microsoft.Owin.FileSystems;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {
public class VirtualPathViewFactory : IVirtualPathViewFactory public class VirtualPathViewFactory : IVirtualPathViewFactory
{ {
private readonly IFileSystem _fileSystem; private readonly IVirtualFileSystem _fileSystem;
private readonly IRazorCompilationService _compilationService; private readonly IRazorCompilationService _compilationService;
public VirtualPathViewFactory(IFileSystem fileSystem, IRazorCompilationService compilationService) public VirtualPathViewFactory(IVirtualFileSystem fileSystem, IRazorCompilationService compilationService)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_compilationService = compilationService; _compilationService = compilationService;

View File

@ -6,7 +6,8 @@ namespace Microsoft.AspNet.Mvc
{ {
public class ViewData : DynamicObject public class ViewData : DynamicObject
{ {
private Dictionary<object, dynamic> _data; private readonly Dictionary<object, dynamic> _data;
private object _model;
public ViewData() public ViewData()
{ {
@ -15,7 +16,14 @@ namespace Microsoft.AspNet.Mvc
public ViewData(ViewData source) public ViewData(ViewData source)
{ {
_data = new Dictionary<object, dynamic>(source._data); _data = source._data;
SetModel(source.Model);
}
public object Model
{
get { return _model; }
set { SetModel(value); }
} }
public dynamic this[string index] public dynamic this[string index]
@ -80,5 +88,13 @@ namespace Microsoft.AspNet.Mvc
this[(string)index] = value; this[(string)index] = value;
return true; return true;
} }
// This method will execute before the derived type's instance constructor executes. Derived types must
// be aware of this and should plan accordingly. For example, the logic in SetModel() should be simple
// enough so as not to depend on the "this" pointer referencing a fully constructed object.
protected virtual void SetModel(object value)
{
_model = value;
}
} }
} }

View File

@ -13,12 +13,16 @@ namespace Microsoft.AspNet.Mvc
{ {
} }
public ViewData(ViewData<TModel> source) public new TModel Model
: base(source)
{ {
Model = source.Model; get { return (TModel)base.Model; }
set { SetModel(value); }
} }
public TModel Model { get; set; } protected override void SetModel(object value)
{
// TODO: Add checks for cast
base.SetModel((TModel)value);
}
} }
} }