Permalink
Browse files

prevents race condition by always returning a new instance of the Cod…

…eDomProvider
  • Loading branch information...
1 parent 9873c61 commit 03935a63c0c182ec5d0c5fd5f341804248709eca @thefringeninja thefringeninja committed Oct 3, 2012
@@ -32,9 +32,12 @@ public string Extension
public RazorEngineHost Host { get; private set; }
/// <summary>
- /// Gets the provider that is used to generate code.
+ /// Creates the provider that is used to generate code.
/// </summary>
- public CodeDomProvider Provider { get; private set; }
+ public CodeDomProvider CreateProvider()
+ {
+ return new CSharpCodeProvider();
+ }
/// <summary>
/// Initializes a new instance of the <see cref="CSharpRazorViewRenderer"/> class.
@@ -46,8 +49,6 @@ public CSharpRazorViewRenderer()
typeof(Microsoft.CSharp.RuntimeBinder.Binder).GetAssemblyPath()
};
- this.Provider = new CSharpCodeProvider();
-
this.Host = new NancyRazorEngineHost(new CSharpRazorCodeLanguage());
this.Host.NamespaceImports.Add("Microsoft.CSharp.RuntimeBinder");
@@ -27,6 +27,6 @@ public interface IRazorViewRenderer
/// <summary>
/// Gets the provider that is used to generate code.
/// </summary>
- CodeDomProvider Provider { get; }
+ CodeDomProvider CreateProvider();
}
}
@@ -134,7 +134,7 @@ private Func<NancyRazorViewBase> GetCompiledViewFactory(string extension, TextRe
var razorResult = engine.GenerateCode(reader, sourceFileName:"placeholder");
- var viewFactory = this.GenerateRazorViewFactory(renderer.Provider, razorResult, referencingAssembly, renderer.Assemblies, passedModelType, viewLocationResult);
+ var viewFactory = this.GenerateRazorViewFactory(renderer.CreateProvider(), razorResult, referencingAssembly, renderer.Assemblies, passedModelType, viewLocationResult);
return viewFactory;
}
@@ -32,7 +32,10 @@ public string Extension
/// <summary>
/// Gets the provider that is used to generate code.
/// </summary>
- public CodeDomProvider Provider { get; private set; }
+ public CodeDomProvider CreateProvider()
+ {
+ return new VBCodeProvider();
+ }
/// <summary>
/// Initializes a new instance of the <see cref="VisualBasicRazorViewRenderer"/> class.
@@ -41,8 +44,6 @@ public VisualBasicRazorViewRenderer()
{
this.Assemblies = new List<string>();
- this.Provider = new VBCodeProvider();
-
this.Host = new NancyRazorEngineHost(new VBRazorCodeLanguage());
}

0 comments on commit 03935a6

Please sign in to comment.