public static IMvcBuilder AddHalJson <TProfile>([NotNull] this IMvcBuilder builder) where TProfile : class, IHalProfile { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddTransient <IHalProfile, TProfile>(); builder.Services.AddSingleton <HalRepositoryBuilder>(); builder.Services.AddTransient <ILinkBuilder <LinkData.Constant>, LinkBuilder.Constant>(); builder.Services.AddTransient <ILinkBuilder <LinkData.Templated>, LinkBuilder.Templated>(); builder.Services.AddTransient <ILinkBuilder <LinkData.Routed>, LinkBuilder.Routed>(); builder.Services.AddSingleton(p => { var profile = p.GetRequiredService <IHalProfile>(); var repoBuilder = p.GetRequiredService <HalRepositoryBuilder>(); return(repoBuilder.Build(profile)); }); return(builder.AddHalJsonFormatter()); }