Pass a Pokedex instance to the GtsRecord ctors

This commit is contained in:
Greg Edwards
2015-04-18 18:40:31 -04:00
parent 4c7e46bcdb
commit 8d8d0e44cc
16 changed files with 196 additions and 82 deletions

30
web/src/AppStateHelper.cs Normal file
View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PkmnFoundations.Data;
namespace PkmnFoundations.Web
{
public static class AppStateHelper
{
public static Pokedex.Pokedex Pokedex(HttpApplicationState application)
{
return GetTypedApplicationObject(application, "pkmncfPokedex", () => new Pokedex.Pokedex(Database.Instance, false));
}
public static T GetTypedApplicationObject<T>(HttpApplicationState application, String key, Func<T> initializer) where T : class
{
object o = application[key];
T t = o as T;
if (t == null)
{
t = initializer();
application.Add(key, t);
}
return t;
}
}
}