public ThingContainerAdapter(ThingContainer container) { this.oddThingsPropertyAdapter = this.CreatePropertyAdapter( nameof(this.OddThings), () => from Thing in container.AllThings where container.EvenThings.Contains(Thing) == false select Thing, value => ThingAdapter.GetInstance(value)); }
internal static async Task InvokeAsync(HttpContext context) { var service = context.RequestServices; var logger = service.GetRequiredService <ILogger <GetAllThings> >(); var things = service.GetRequiredService <IEnumerable <Thing> >(); logger.LogInformation("Request all things."); await context.WriteBodyAsync(HttpStatusCode.OK, things.Select(thing => { ThingAdapter.Adapt(context, thing); return(thing.ThingContext.Response); })).ConfigureAwait(false); }
public static ThingAdapter GetInstance(Thing thing) { ThingAdapter TheThingAdapter; if (ThingAdapter.instances.ContainsKey(thing)) { TheThingAdapter = ThingAdapter.instances[thing]; } else { TheThingAdapter = new ThingAdapter(thing); ThingAdapter.instances.Add(thing, TheThingAdapter); } return(TheThingAdapter); }
internal static async Task InvokeAsync(HttpContext context) { var service = context.RequestServices; var logger = service.GetRequiredService <ILogger <GetThing> >(); var things = service.GetRequiredService <IEnumerable <Thing> >(); var name = context.GetRouteData <string>("name"); logger.LogInformation("Requesting Thing. [Thing: {name}]", name); var thing = things.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (thing == null) { logger.LogInformation("Thing not found. [Thing: {name}]", name); context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } ThingAdapter.Adapt(context, thing); logger.LogInformation("Found 1 Thing. [Thing: {name}]", thing.Name); await context.WriteBodyAsync(HttpStatusCode.OK, thing.ThingContext.Response) .ConfigureAwait(false); }