ServiceStack/ServiceStack — pull request #572 by bchavez (2013-04-05 09:11:00+00:00)
Title: Allows Sequential Compilation in DebugMode

## Tiny Problem

ServiceStack overwrites specified `CompileInParallelWithNoOfThreads` values.

Consider the following ServiceStack configuration code:
```cs
public class HelloAppHost : AppHostBase
{
public override void Configure( Funq.Container container )
{
var razor = new RazorFormat
{
TemplateProvider =
{
CompileInParallelWithNoOfThreads = 0
}
};

this.Plugins.Add( razor );

this.Routes.Add( "/hello" );
this.Routes.Add( "/hello/{Name}" );
}
}
```

I'd like ServiceStack to compile my Razor pages sequentially **while in DebugMode** to help simplify some debugging and page compilation errors.

Currently, **ServiceStack** ***overwrites*** my setting in the RazorPlugin's `Configure` method:

```cs
public class RazorFormat : IRazorViewEngine, IPlugin, IRazorPlugin
{
public void Configure(IAppHost appHost)
{
this.AppHost = appHost;
appHost.ViewEngines.Add(this);

//Default to watching modfied pages in DebugMode
if (!WatchForModifiedPages)
WatchForModifiedPages = appHost.Config.DebugMode;

//Default to parallel execution in DebugMode
if (this.TemplateProvider.CompileInParallelWithNoOfThreads <= 0)
this.TemplateProvider.CompileInParallelWithNoOfThreads = appHost.Config.DebugMode
? Environment.ProcessorCount * 2
: 0;

```

In my case, sets `CompileInParallelWithNoOfThreads = 24` on my 6 core processor CPU with HT. :(

## Patch
This pull request resolves the issue by tweaking the `CompileInParallelWithNoOfThreads` into a nullable `int?` type so that values already set are not overwritten:

```cs
if (!this.TemplateProvider.CompileInParallelWithNoOfThreads.HasValue)
this.TemplateProvider.CompileInParallelWithNoOfThreads = appHost.Config.DebugMode
? Environment.ProcessorCount * 2
: 0;
```