/// <summary> /// Configure read and write models /// </summary> public static void ConfigureModels(this IApplicationBuilder app, TeamRepository repo, TeamsView teamsView, TeamCommandHandler commandHandler) { // Read models (Queries) setup var snapshot = // Current data snapshot: we retrieve all the aggregates from the repository repo.GetIds(0, int.MaxValue).ToArray() .Select(id => repo.Find(id)) .Select(x => new ReadModel.Teams.DTO.TeamDto(x)); teamsView.LoadSnapshot(snapshot); // Write models (Commands) setup // Nothing to do (handler registration is done in the TeamCommandHandler constructor) // Note that although not used, the dependency on TeamCommandHandler as a parameters to this method forces its instantiation // (otherwise - unless used elsewhere - the DI system would never invoke the implementation factory delegate passed to AddSingleton) }