public void ShouldThrowExceptionWhenProviderIsCreatedTwice() { var container = new ServiceContainer(); var serviceCollection = new ServiceCollection(); var provider = container.CreateServiceProvider(serviceCollection); Assert.Throws <InvalidOperationException>(() => container.CreateServiceProvider(serviceCollection)); }
public void ShouldThrowExceptionWhenProviderIsCreatedTwiceAndCurrentScopeIsDisabled() { var container = new ServiceContainer(c => c.EnableCurrentScope = false); var serviceCollection = new ServiceCollection(); var provider = container.CreateServiceProvider(serviceCollection); Assert.Throws <InvalidOperationException>(() => container.CreateServiceProvider(serviceCollection)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc() /*.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)*/; services.AddSingleton <IEnumerable <IFoo> >(sp => new[] { new Foo() }); services.AddSingleton <LocalizedDescriptionResolver>(); services.AddAutoMapper(); //Toggle this to see the difference in memory usage. bool useExplicitEnumerable = true; var options = new ContainerOptions() { EnablePropertyInjection = false, LogFactory = type => logEntry => Debug.WriteLine(logEntry.Message) }; if (!useExplicitEnumerable) { options.DefaultServiceSelector = servicesNames => servicesNames.Last(); } var serviceContainer = new ServiceContainer(options) { ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider() }; var lightInjectServiceProvider = serviceContainer.CreateServiceProvider(services, useExplicitEnumerable); return(lightInjectServiceProvider); }
public static IServiceProvider Init(string connectionString, string dbORM) { //Note: The default behavior in LightInject is to treat all objects as transients. var serviceCollection = new ServiceCollection(); // The Microsoft.Extensions.Logging package provides this one-liner to have logging services. serviceCollection.AddLogging(); var options = ContainerOptions.Default.WithMicrosoftSettings(); options.EnablePropertyInjection = true; var container = new ServiceContainer(options); RegisterDbConnectionProvider(container, connectionString); container.AddJsonFile("ioc_modules.json"); if (dbORM == "efcore") { container.RegisterFrom <EfRegistrationModule>(); } else { container.RegisterFrom <NHibernateRegistrationModule>(); } return(container.CreateServiceProvider(serviceCollection)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvc().AddControllersAsServices(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); var containerOptions = new ContainerOptions { EnablePropertyInjection = false }; var container = new ServiceContainer(containerOptions) { ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider() }; container.RegisterFrom <LightInjectModule>(); container.RegisterInstance <IAppSettingsRetriever>(new AppSettingsRetriever(Configuration)); container.Register <IHttpContextAccessor, HttpContextAccessor>(new PerContainerLifetime()); return(container.CreateServiceProvider(services)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(c => c.Conventions.Add(new ApiExplorerGroupPerVersionConvention())) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddControllersAsServices(); services.AddCors(); services.AddApiVersioning(o => { o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(1, 0); o.ReportApiVersions = true; }); services.AddEntityFrameworkInMemoryDatabase(); services.AddDbContextPool <MarketingDbContext>((serviceProvider, options) => { options.UseInMemoryDatabase("MarketingDb"); options.UseInternalServiceProvider(serviceProvider); }); services.AddMarketingServices(); services.RegisterSwaggerDoc(); services.RegisterMapperConfiguration(); var containerOptions = new ContainerOptions { EnablePropertyInjection = false }; var container = new ServiceContainer(containerOptions); return(container.CreateServiceProvider(services)); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 /// <summary> /// Configure .NET DI Services /// </summary> /// <remarks>This API will register all the DI services.</remarks> /// <param name="services"></param> public IServiceProvider ConfigureServices(IServiceCollection services) { #region LightInject Configuration var containerOptions = new ContainerOptions { EnablePropertyInjection = false }; var container = new ServiceContainer(containerOptions); #endregion var sqlConnection = Configuration.GetConnectionString("InventoryDb"); services.AddDbContext <InventoryDbContext>(options => options.UseSqlServer(sqlConnection)); var sqlLogConnection = Configuration.GetConnectionString("LogManagerDb"); services.AddDbContext <LogManagerDbContext>(options => options.UseSqlServer(sqlLogConnection)); //Register your own services within LightInject container.Register <IUnitOfWork, UnitOfWork <InventoryDbContext> >(); services.AddRouting(); services.AddMvc(options => { options.RespectBrowserAcceptHeader = true; // false by default options.Filters.Add(typeof(LogActionFilter)); }).AddControllersAsServices(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <LogFilter>(); services.AddSwaggerGen(c => { c.AddSecurityDefinition("Bearer", new Swashbuckle.AspNetCore.Swagger.ApiKeyScheme() { Description = "Authorization format : Bearer {token}", Name = "Authorization", In = "header", Type = "apiKey" }); c.SwaggerDoc("v1", new Info { Version = "v1", Title = "Inventory Web API", Description = "An ASP.NET Core 2.0 Template", TermsOfService = "None", Contact = new Contact() { Name = "KantiKiran Bhupathi", Email = "*****@*****.**", Url = "https://www.linkedin.com/in/kanti-kiran-bhupathi-a9a5028/" } }); c.IncludeXmlComments(GetXmlCommentsPath()); c.DescribeAllEnumsAsStrings(); }); return(container.CreateServiceProvider(services)); }
/// <summary> /// Create a new <see cref="IServiceProvider"/> from the given <paramref name="serviceCollection"/>. /// </summary> /// <param name="serviceCollection">The <see cref="IServiceCollection"/> from which to create an <see cref="IServiceProvider"/>.</param> /// <param name="options">The <see cref="ContainerOptions"/> to be used when creating the <see cref="ServiceContainer"/>.</param> /// <returns>An <see cref="IServiceProvider"/> that is backed by an <see cref="IServiceContainer"/>.</returns> public static IServiceProvider CreateLightInjectServiceProvider(this IServiceCollection serviceCollection, ContainerOptions options) { var clonedOptions = options.Clone(); clonedOptions.WithMicrosoftSettings(); var container = new ServiceContainer(clonedOptions); return(container.CreateServiceProvider(serviceCollection)); }
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) { var container = new ServiceContainer(new ContainerOptions() { EnablePropertyInjection = false, DefaultServiceSelector = services => services.SingleOrDefault(string.IsNullOrWhiteSpace) ?? services.Last() }); return(container.CreateServiceProvider(serviceCollection)); }
public IServiceProvider ConfigureServices(IServiceCollection services) { //TODO: remove commented lines to enable odata services.AddOData(); services.AddMvc().AddControllersAsServices(); var container = new ServiceContainer(new ContainerOptions().WithMicrosoftSettings()); container.Register <IService, Service>(); return(container.CreateServiceProvider(services)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var containerOptions = new ContainerOptions { EnablePropertyInjection = false, DefaultServiceSelector = serviceNames => serviceNames.SingleOrDefault(string.IsNullOrWhiteSpace) ?? serviceNames.Last() }; var container = new ServiceContainer(containerOptions); return(container.CreateServiceProvider(services)); }
public static IServiceProvider CreateLightInjectServiceProvider(this IServiceCollection services) { var containerOptions = new ContainerOptions { EnablePropertyInjection = false }; var container = new ServiceContainer(containerOptions); container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider(); return(container.CreateServiceProvider(services)); }
/// <summary> /// Create LightInject service provider that resolves objects. /// </summary> /// <param name="serviceCollection">The current registered services.</param> public static IServiceProvider Create(IServiceCollection serviceCollection) { // Create DI container. // Property injection causes recursive dependency with ServiceType:Microsoft.AspNetCore.Razor.Language.RazorEngine. ServiceContainer container = new ServiceContainer(new ContainerOptions { EnablePropertyInjection = false }); container.RegisterServices(); IServiceProvider serviceProvider = container.CreateServiceProvider(serviceCollection); return(serviceProvider); }
public void ShouldCreateEnumerableRegistrationForGenericTypes() { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IFoo <int>, Foo <int> >(); serviceCollection.AddSingleton <IFoo <int>, AnotherFoo <int> >(); var container = new ServiceContainer(); container.CreateServiceProvider(serviceCollection); var enumerableRegistration = container.AvailableServices.SingleOrDefault(sr => sr.ServiceType == typeof(IEnumerable <IFoo <int> >)); Assert.NotNull(enumerableRegistration); }
public IServiceProvider ConfigureServices(IServiceCollection services) { // Create Container wrapper over IServiceCollection var container = new ServiceContainer(services); container.RegisterInstance <IServiceContainer>(container); // Configurring container AppStarter.Init(container); // Apply all services registered through the IServiceCollection and return IServiceProvider return(container.CreateServiceProvider()); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { ConfigureOptions(services); services.AddAuthentication(); services.AddAuthorization(); services.AddMvc(o => { o.Filters.Add(new CustomExceptionFilterAttribute()); o.Filters.Add(new ValidationAttribute()); o.UseFromBodyBinding(); }); //.AddControllersAsServices(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); c.OperationFilter <AuthorizationHeaderParameterOperationFilter>(); }); var connectionString = Configuration.GetConnectionString("GaverContext"); if (connectionString.IsNullOrEmpty()) { throw new ConfigurationException("ConnectionStrings:GaverContext"); } services.AddEntityFrameworkNpgsql() .AddDbContext <GaverContext>(options => options .UseNpgsql(connectionString, b => b .MigrationsAssembly(GetType().GetTypeInfo().Assembly.FullName)), ServiceLifetime.Transient); services.AddSingleton <IMapperService, MapperService>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // services.AddSignalR(options => options.RegisterInvocationAdapter<CustomJsonNetInvocationAdapter>("json")); // services.AddSingleton<IConfigureOptions<SignalROptions>, CustomSignalROptionsSetup>(); // services.AddSingleton(factory => new JsonSerializer { // ContractResolver = new SignalRContractResolver() // }); services.AddMediatR(); var container = new ServiceContainer(new ContainerOptions { EnablePropertyInjection = false, EnableVariance = false, LogFactory = type => entry => Log.Logger.ForContext(type).Write(entry.Level.ToSerilogEventLevel(), entry.Message) }); container.ScopeManagerProvider = new StandaloneScopeManagerProvider(); container.RegisterAssembly <ILogicAssembly>(); container.RegisterAssembly <Startup>(); return(container.CreateServiceProvider(services)); }
protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection) { System.Diagnostics.Debugger.Launch(); var container = new ServiceContainer() { PropertyDependencySelector = new PropertyInjectionDisabler() }; var lightInjectProvider = container.CreateServiceProvider(serviceCollection); var microsoftProvider = serviceCollection.BuildServiceProvider(); var t = lightInjectProvider.GetService <BaseCorePipelineManager>(); var t1 = microsoftProvider.GetService <BaseCorePipelineManager>(); return(lightInjectProvider); }
public static IServiceProvider AddInternalServices( this IServiceCollection services, IConfiguration configuration, string connectionString) { services .Configure <AppSettings>(configuration.GetSection("AppSettings")) .AddSingleton <IAuthorizationHandler, FunctionPermissionHandler>() .AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); var container = new ServiceContainer(new ContainerOptions { EnablePropertyInjection = false }); container .SetDefaultLifetime <PerScopeLifetime>() // Infrastructure. .Register <IMemoryCacheService, MemoryCacheService>() // IdentityServer4. .Register <ICorsPolicyService, InMemoryCorsPolicyService>() .Register <IProfileService, ProfileService>() // Emails. .Register <IEmailSender, NetEmailSender>() .Register <IEmailAccountService, EmailAccountService>() .Register <IQueuedEmailService, QueuedEmailService>() // Logs. .Register <IActivityLogService, ActivityLogService>() .Register <ILogService, LogService>() //Blobs. .Register <IBlobService, BlobService>() // News. .Register <INewsService, NewsService>(); container // Background tasks. .Register <IHostedService, QueuedEmailSendTask>(new PerContainerLifetime()) // AppSettings. .Register(factory => factory.GetInstance <IOptionsSnapshot <AppSettings> >().Value, new PerContainerLifetime()) // AspNet Identity. .Register <IUserStore <AppUser> >(factory => GetUserCollection(connectionString), new PerContainerLifetime()) .Register <IRoleStore <AppRole> >(factory => GetRoleCollection(connectionString), new PerContainerLifetime()) // IdentityServer4. .Register <IResourceStore, MongoDbResourceStore>(new PerContainerLifetime()) .Register <IClientStore, MongoDbClientStore>(new PerContainerLifetime()) .Register <IPersistedGrantStore, MongoDbPersistedGrantStore>(new PerContainerLifetime()); return(container.CreateServiceProvider(services)); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); var containerOptions = new ContainerOptions { EnablePropertyInjection = false }; var container = new ServiceContainer(containerOptions); container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider(); ServiceLibrary.IoC.IoCRegister.Register(container); DataAccess.RestClient.IoC.IoCRegister.Register(container); return(container.CreateServiceProvider(services)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc() //.SetCompatibilityVersion(CompatibilityVersion.Version_2_1) ; var container = new ServiceContainer(); return(container.CreateServiceProvider(services)); }
public static IServiceProvider AddInternalServices(this IServiceCollection services) { var container = new ServiceContainer(new ContainerOptions { EnablePropertyInjection = false }); container .SetDefaultLifetime <PerScopeLifetime>() // Infrastructure. .Register <IMemoryCacheService, MemoryCacheService>() // Logs. .Register <IActivityLogTypeService, ActivityLogTypeService>() .Register <IActivityLogService, ActivityLogService>() .Register <ILogService, LogService>(); return(container.CreateServiceProvider(services)); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().AddApplicationPart(typeof(Startup).Assembly); services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); }); AddSwaggerConfiguration(services); var container = new ServiceContainer(new ContainerOptions() { EnablePropertyInjection = false }); container.Register(factory => CreateConfiguration(), new PerContainerLifetime()); container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider(); container.RegisterFrom <CompositionRoot>(); return(container.CreateServiceProvider(services)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { var containerOptions = new ContainerOptions { EnablePropertyInjection = false }; var serviceContainer = new ServiceContainer(containerOptions); //Register your own services within LightInject serviceContainer.RegisterModule(new InfrastructureModule()) .RegisterModule(new DataModule()) .RegisterModule(new CoreModule()) .RegisterModule(new WebModule()); serviceContainer.GetInstance <IAppInitializer>() .Start(); services.AddMvc() .AddControllersAsServices(); //Build and return the Service Provider return(serviceContainer.CreateServiceProvider(services)); }
/// <summary> /// Create LightInject service provider that resolve objects. /// </summary> /// <param name="serviceCollection">The service collection.</param> /// <returns>LightInject service provider with already registered services.</returns> public static IServiceProvider CreateDIProvider(this IServiceCollection serviceCollection) { var container = new ServiceContainer(new ContainerOptions() { EnablePropertyInjection = false }); container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider(); // Register all data repositories. container.RegisterAssembly(Load(Constants.Recruitment_DATA_ASSEMBLY_NAME), CreateScopeLifetyme, FilterByCoreInterfaces); // Register all services. container.RegisterAssembly(Load(Constants.Recruitment_BUSINESS_ASSEMBLY_NAME), CreateScopeLifetyme, FilterByCoreInterfaces); // Add context accessors serviceCollection.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); serviceCollection.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); return(container.CreateServiceProvider(serviceCollection)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); // Add framework services. services.AddSingleton <IThingsRepository, ThingsRepository>(); services.AddMvc(); // Configure Mapster ConfigureMapster(); // Setup IoC var container = new ServiceContainer(new ContainerOptions() { EnablePropertyInjection = false }); container.Register <IAssignmentRepository, AssignmentRepository>(); container.RegisterInstance(CreateDatabaseInstance(HostingEnvironment)); IAdapter adapter = new Adapter(); container.RegisterInstance(adapter); container.ScopeManagerProvider = new StandaloneScopeManagerProvider(); return(container.CreateServiceProvider(services)); }
private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); #if DEBUG // for manually testing different cultures //SetupCulture("de-DE"); #endif Core.Application.SetPaths( Application.StartupPath, System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HFM")); using (var container = new ServiceContainer()) { var bootStrapper = new BootStrapper(args, container); try { container.RegisterAssembly(Assembly.GetExecutingAssembly()); // wires up IServiceProvider and IServiceScopeFactory _ = container.CreateServiceProvider(new EmptyServiceCollection()); Forms.TypeDescriptionProviderSetup.Execute(); bootStrapper.Execute(); } catch (Exception ex) { bootStrapper.ShowStartupException(ex); return; } if (bootStrapper.MainForm != null) { Application.Run(bootStrapper.MainForm); } } }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { var container = new ServiceContainer { ScopeManagerProvider = new StandaloneScopeManagerProvider() }; // Configure and register Serilog. Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.LiterateConsole() .CreateLogger(); container.RegisterInstance(Log.Logger); // Configure and register Darker. var queryProcessor = QueryProcessorBuilder.With() .LightInjectHandlers(container, opts => opts .WithQueriesAndHandlersFromAssembly(typeof(GetPeopleQueryHandler).GetTypeInfo().Assembly)) .InMemoryQueryContextFactory() .JsonQueryLogging() .Policies(ConfigurePolicies()) .Build(); container.RegisterInstance(queryProcessor); // Don't forget to register the required decorators. todo maybe find a way to auto-discover these container.Register(typeof(QueryLoggingDecorator <,>)); container.Register(typeof(RetryableQueryDecorator <,>)); container.Register(typeof(FallbackPolicyDecorator <,>)); // Add framework services. services.AddMvc(); return(container.CreateServiceProvider(services)); }
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) { var container = new ServiceContainer(); return(container.CreateServiceProvider(serviceCollection)); }
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) { var container = new ServiceContainer(); return container.CreateServiceProvider(serviceCollection); }
private void RegisterAspNetCore() { container.CreateServiceProvider(CreateServiceCollection()); }
public IServiceProvider ConfigureServices(IServiceCollection services) { var container = new ServiceContainer(); container.EnableAnnotatedPropertyInjection(); // services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //Injeção de dependência para repositórios container.Register(typeof(IRepository <>), typeof(AbstractRepository <>)); container.Register <IMongoContext, MongoContext>(new PerRequestLifeTime()); container.Register <ICityRepository, CityRepository>(new PerRequestLifeTime()); container.Register <ITheaterRepository, TheaterRepository>(new PerRequestLifeTime()); container.Register <ILocationRepository, LocationRepository>(new PerRequestLifeTime()); container.Register <IMovieRepository, MovieRepository>(new PerRequestLifeTime()); container.Register <ISessionRepository, SessionRepository>(new PerRequestLifeTime()); // container.Register<IConfigurationCollection, ConfigurationCollection>(new PerRequestLifeTime()); //Injeção de dependência para serviços container.Register(typeof(IBaseService <>), typeof(BaseService <>)); container.Register <ICityService, CityService>(new PerRequestLifeTime()); container.Register <ITheaterService, TheaterService>(new PerRequestLifeTime()); container.Register <ILocationService, LocationService>(new PerRequestLifeTime()); container.Register <IMovieService, MovieService>(new PerRequestLifeTime()); container.Register <ISessionService, SessionService>(new PerRequestLifeTime()); //Injeção de dependência para aplicação container.Register(typeof(IBaseAppService <>), typeof(BaseAppService <>)); container.Register <ICityAppService, CityAppService>(new PerRequestLifeTime()); container.Register <ITheaterAppService, TheaterAppService>(new PerRequestLifeTime()); container.Register <ILocationAppService, LocationAppService>(new PerRequestLifeTime()); container.Register <IMovieAppService, MovieAppService>(new PerRequestLifeTime()); container.Register <ISessionAppService, SessionAppService>(new PerRequestLifeTime()); // services.AddScoped<IMongoContext, MongoContext>(); services.AddMvc(options => { options.Filters.Add(new GlobalExceptionFilter()); }).AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); options.SerializerSettings.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii; options.SerializerSettings.NullValueHandling = NullValueHandling.Include; }).AddControllersAsServices(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Management System API", Version = "v1" }); }); services.AddSingleton <IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService)); services.AddSingleton <IDocumentExecuter, DocumentExecuter>(); services.AddSingleton <IDocumentWriter, DocumentWriter>(); services.AddSingleton <GraphQLQuery>(); services.AddSingleton <GraphQLData>(); services.AddSingleton <CityType>(); services.AddSingleton <CityInterface>(); services.AddSingleton <ISchema, GraphQLSchema>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddGraphQL(_ => { _.EnableMetrics = true; _.ExposeExceptions = true; }) .AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User }); return(container.CreateServiceProvider(services)); }