Esempio n. 1
0
        public static void Initialize(IServiceCollection services, HostBuilderContext hostContext)
        {
            services.AddMemoryCache();
            CreateConfigurations(services, hostContext);

            #region services
            services.AddSingleton <IOutgoingServicePool, OutgoingServicePool>();
            #endregion

            #region behavior
            services.AddTransient <IBehaviorExecutor, BehaviorExecutor>();
            #endregion

            #region interpreter
            services.AddTransient <IInterpreter, InterpreterRuntime>();
            services.AddSingleton <IExpressionFactory, ExpressionFactory>();
            #endregion

            #region repositories
            services.AddSingleton <IConnectionsRepository, ConnectionsRepository>();
            services.AddSingleton <IDialogsRepository, DialogsRepository>();
            #endregion

            DatabaseDI.ConfigureDatabase(services, hostContext.Configuration);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DatabaseDI.ConfigureDatabase(services, Configuration, ServiceLifetime.Scoped);
            services.AddMemoryCache();

            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                {
                    builder.AllowAnyOrigin();
                    builder.AllowAnyHeader();
                    builder.AllowAnyMethod();
                });
            });

            services.AddControllers(c =>
            {
                c.RespectBrowserAcceptHeader = true;
                c.ReturnHttpNotAcceptable    = true;
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Counselor.Platform.Api", Version = "v1"
                });
            });

            services.AddResponseCaching();

            services.AddAuthentication("BasicAuthentication")
            .AddScheme <AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);

            services.AddScoped <IUserService, UserService>();
            services.AddScoped <ITransportService, TransportService>();
            services.AddScoped <IEntitiesService, EntitiesService>();
            services.AddScoped <IDialogService, DialogService>();
            services.AddScoped <IScriptService, ScriptService>();
            services.AddScoped <IBotService, BotService>();
        }