// 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 void ConfigureServices(IServiceCollection services) { services.AddControllers().AddNewtonsoftJson(options => { options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; options.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto; }); this.ConfigureSecurity(services); MongoDBConfig config = new MongoDBConfig(); this.Configuration.Bind("MongoDB", config); System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); services.AddScoped <Entities.DataContext>((_) => new DataContext(config)); services.AddScoped <UsersManager>(); services.AddScoped <MissionsManager>(); services.AddScoped <ObservationsManager>(); services.AddScoped <SpeciesManager>(); services.AddScoped <FileManager>(); services.AddScoped <TitlesManager>(); services.AddScoped <FoliaManager>(); services.AddSignalR(); services.AddSingleton <HubConnectionManager>(); services.AddSingleton <HubPositionManager>(); services.AddSingleton <IUserNotify, NotifyHub>(); services.AddSingleton <IUserPosition, PositionHub>(); services.AddScoped <IAuthorizationHandler, RolesAuthorizationHandler>(); var fs = new FoliaScript(this.Configuration["FoliaPath"]); services.AddSingleton <FoliaScript>(fs); var engine = new RazorLightEngineBuilder() .UseEmbeddedResourcesProject(typeof(Business.ObservationsManager)) .Build(); services.AddSingleton <IRazorLightEngine>(engine); var mongoUrlBuilder = new MongoUrlBuilder($"{config.ConnectionString}/Albiziapp"); var mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl()); // Add Hangfire services. Hangfire.AspNetCore nuget required services.AddHangfire(configuration => configuration .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseMongoStorage(mongoClient, mongoUrlBuilder.DatabaseName, new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { MigrationStrategy = new MigrateMongoMigrationStrategy(), BackupStrategy = new CollectionMongoBackupStrategy() }, Prefix = "hangfire.mongo", CheckConnection = true }) ); // Add the processing server as IHostedService services.AddHangfireServer(serverOptions => { serverOptions.ServerName = "Hangfire.Mongo server 1"; }); services.AddSwaggerGen(); }
public FoliaManager(FoliaScript folia, FileManager fileManager, UsersManager usersManager) { this.Folia = folia; this.FileManager = fileManager; this.UsersManager = usersManager; }