Skip to content

Instantly share code, notes, and snippets.

View ahjohannessen's full-sized avatar

Alex Henning Johannessen ahjohannessen

View GitHub Profile
@ahjohannessen
ahjohannessen / FindInterceptorFix.cs
Created November 27, 2010 04:29
Fixes threading issue.
public CompoundInterceptor FindInterceptor(Type type)
{
CompoundInterceptor interceptor;
if (!_analyzedInterceptors.TryGetValue(type, out interceptor))
{
lock (_locker)
{
if (!_analyzedInterceptors.TryGetValue(type, out interceptor))
{
TypeInterceptor[] interceptorArray = _interceptors.FindAll(i => i.MatchesType(type)).ToArray();
@ahjohannessen
ahjohannessen / Rock.spark
Created November 29, 2010 16:03
Showcase of odd this.Partial extension method.
<viewdata model="FubuMVC.HelloSpark.Controllers.EarthViewModel" />
<content:title>Down to Earth!</content:title>
<content:header>Where are we now?</content:header>
<h2>Via Spark Partial: <WhereAreWe /></h2>
<h2>Via Fubu Partial:
#this.Partial<LocationViewModel>();
#this.Partial<LocationViewModel>();
</h2>
@ahjohannessen
ahjohannessen / Memoization.cs
Created January 19, 2011 17:42
Memoization
public static class Memoization
{
public static Func<TA, TR> Memoize<TA, TR>(Func<TA, TR> f)
{
var map = new Dictionary<TA, TR>();
return a =>
{
lock (map)
{
// In a StructureMap registry somewhere (for us, it's in CoreRegistry.cs)
For<IObjectConverter>().Use<DovetailObjectConverter>();
// In another file, we set up some of our conversions and conversion families
public class DovetailObjectConverter : ServiceEnabledObjectConverter
{
public DovetailObjectConverter(IServiceLocator locator)
: base(locator)
{
public class EntityModelBinder : IModelBinder
{
private static readonly TypeConverter _converter = TypeDescriptor.GetConverter(typeof (Guid));
public bool Matches(Type type)
{
return type.CanBeCastTo<DomainEntity>();
}
@ahjohannessen
ahjohannessen / SparkLoader.cs
Created February 20, 2011 22:26
Spark caching
using System.Collections.Generic;
using System.Linq;
using Spark;
using Spark.Compiler;
using Spark.Web.FubuMVC;
using Spark.Web.FubuMVC.ViewCreation;
using Spark.Web.FubuMVC.ViewLocation;
namespace ZG.Mvc.Theming.Views.Spark
{
@ahjohannessen
ahjohannessen / SparkFinder.cs
Created April 19, 2011 22:24
SparkFinder.cs
public class SparkFinder
{
private readonly SparkItems _items;
private readonly string[] _sharedFolderNames;
public SparkFinder(SparkItems items, string[] sharedFolderNames)
{
_items = items;
_sharedFolderNames = sharedFolderNames;
}
@ahjohannessen
ahjohannessen / Funky.cs
Created April 25, 2011 23:19
Func<Stream>
public Func<Stream> Execute()
{
var writer = new StringWriter();
var view = (SparkViewBase)_provider.GetView();
_partialOutput.SetWriter(() => view.Output);
view.Output = writer;
// something a la this:
return () =>
@ahjohannessen
ahjohannessen / FunkyToo.cs
Created April 25, 2011 23:22
Func<TextWriter>
public Func<TextWriter> Execute()
{
var writer = new StringWriter();
var view = (SparkViewBase)_provider.GetView();
_partialOutput.SetWriter(() => view.Output);
view.Output = writer;
return () =>
{
@ahjohannessen
ahjohannessen / FubuBindingProvider.cs
Created May 4, 2011 14:44
Temporary impl of binding provider
// Temporary : Needs discussion + test coverage (if used)
public class FubuBindingProvider : BindingProvider
{
private readonly ISparkItems _sparkItems;
public FubuBindingProvider (ISparkItems sparkItems)
{
_sparkItems = sparkItems;
}