public Dungeon GetDungeon(string id) { using (TinyIoCContainer requestContainer = _container.GetChildContainer()) { Dungeon result = null; IDungeonDepot depot = requestContainer.Resolve <IDungeonDepot>(); if (depot.ContainsKey(id)) { DungeonConfigEntity dungeonConfig = depot[id]; requestContainer.Register <DungeonConfigEntity>(dungeonConfig); //TODO: Pull the generator by name stored in the config IDungeonGenerator generator = requestContainer.Resolve <IDungeonGenerator>(); result = generator.Generate(); } else if (id == _defaultId) { // return the default dungeon result = new Dungeon(_defaultId, _defaultSize, _defaultSize); } else { throw new WebFaultException <string>( string.Format("No dungeon exists with id {0}", id), HttpStatusCode.NotFound); } return(result); } }
public string CreateDungeon(DungeonConfig configuration) { //use a child container for this request which will dispose everything using (TinyIoCContainer requestContainer = _container.GetChildContainer()) { //register the requested config for others to find it requestContainer.Register <DungeonConfig>(configuration); string id = requestContainer.Resolve <IIdGenerator>().GetNextId(configuration.Name); DungeonConfigEntity dungeonConfig = requestContainer.Resolve <DungeonConfigEntity>(); IDungeonDepot depot = requestContainer.Resolve <IDungeonDepot>(); depot.Add(id, dungeonConfig); return(id); } }