예제 #1
0
 public void AddServices_MustOk()
 {
     AppEngine.Reset();
     AppEngine.AddServices(Easy.NetworkAdapterTypes.HttpClient);
     AppEngine.Reset();
     AppEngine.AddServices(Easy.NetworkAdapterTypes.WebRequest);
     AppEngine.Reset();
 }
예제 #2
0
 public WebModuleEntry AddComicAnalysis(IServiceCollection services)
 {
     AppEngine.Reset(services);
     AppEngine.AddServices(NetworkAdapterTypes.HttpClient);
     services.AddSingleton <ProposalEngine>();
     services.AddScoped <IComicVisiting <Stream>, WebComicVisiting>();
     services.AddKnowEngines();
     return(this);
 }
예제 #3
0
파일: App.axaml.cs 프로젝트: Cricle/Anf
        private void InitServices()
        {
            AppEngine.Reset();
            AppEngine.AddServices(NetworkAdapterTypes.WebRequest);
            //var store = new GzipFileStoreService(new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, XComicConst.CacheFolderName)), MD5AddressToFileNameProvider.Instance);
            var store = FileStoreService.FromMd5Default(Path.Combine(Workstation, XComicConst.CacheFolderName));
            var hp    = new Lazy <HomePage>(() => new HomePage());
            var cv    = new Lazy <ComicView>(() => new ComicView());
            var bv    = new Lazy <BookshelfView>(() => new BookshelfView());
            var va    = new ViewActiver <IControl>
            {
                [typeof(HomePage)]      = () => hp.Value,
                [typeof(ComicView)]     = () => cv.Value,
                [typeof(BookshelfView)] = () => bv.Value
            };
            var nav = new MainNavigationService(new Border(), va);

            AppEngine.Services.AddSingleton(x => new BookManager(new DirectoryInfo(Path.Combine(Workstation, XComicConst.BookFolderName)), x.GetRequiredService <RecyclableMemoryStreamManager>()));
            AppEngine.Services.AddSingleton <IViewActiver <IControl> >(va);
            AppEngine.Services.AddSingleton <ThemeService>();
            AppEngine.Services.AddSingleton <TitleService>();
            AppEngine.Services.AddSingleton <IComicTurnPageService>(nav);
            AppEngine.Services.AddSingleton(nav);
            AppEngine.Services.AddScoped <RemoteEngine>();
            AppEngine.Services.AddSingleton <IComicSaver>(store);
            AppEngine.Services.AddSingleton <IStoreService>(store);
            AppEngine.Services.AddSingleton <IPlatformService, PlatformService>();
            AppEngine.Services.AddSingleton <IStreamImageConverter <Bitmap>, StreamImageConverter>();
            AppEngine.Services.AddSingleton <IResourceFactoryCreator <Bitmap>, PlatformResourceCreatorFactory <Bitmap, Bitmap> >();
            AppEngine.Services.AddSingleton <ExceptionService>();
            var storeSer = new WithImageComicStoreService <Bitmap, Bitmap>(new DirectoryInfo(Path.Combine(Workstation, XComicConst.CacheFolderName, XComicConst.StoreFolderName)));

            AppEngine.Services.AddSingleton(storeSer);
            AppEngine.Services.AddSingleton <IObservableCollectionFactory>(new AvaloniaObservableCollectionFactory());
            AppEngine.Services.AddSingleton <ComicStoreService <WithImageComicStoreBox <Bitmap, Bitmap> > >(storeSer);
            AppEngine.Services.AddSingleton(HistoryService.FromFile(Path.Combine(Workstation, HistoryService.HistoryFileName)));
            AppEngine.Services.AddSingleton <ProposalEngine>();
            AppEngine.Services.AddScoped <IComicVisiting <Bitmap>, DesktopStoreComicVisiting>();
            AppEngine.Services.AddScoped <StoreComicVisiting <Bitmap> >();

            var configRoot = BuildConfiguration();

            AppEngine.Services.AddSingleton(CreateSettings);
            AppEngine.Services.AddSingleton(configRoot);
            AppEngine.Services.AddSingleton <IConfiguration>(configRoot);
            AppEngine.Services.AddSingleton <IConfigurationRoot>(configRoot);
            AppEngine.Services.AddLogging(x =>
            {
                x.ClearProviders();
                x.AddNLog("NLog.config");
            });
        }
예제 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            AppEngine.Reset(services);
            AppEngine.AddServices(NetworkAdapterTypes.HttpClient);
            var store = FileStoreService.FromMd5Default(Path.Combine(Environment.CurrentDirectory, XComicConst.CacheFolderName));

            services.AddSingleton <IComicSaver>(store);
            services.AddSingleton <IStoreService>(store);
            services.AddSingleton <IResourceFactoryCreator <Stream>, WebResourceFactoryCreator>();
            services.AddSingleton <ProposalEngine>();
            services.AddScoped <IComicVisiting <Stream>, WebComicVisiting>();
            services.AddKnowEngines();
            services.AddControllersWithViews();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTSCONNECTIONSTRING"]);
            services.AddSignalR()
            .AddAzureSignalR(opt =>
            {
                opt.ConnectionString = Configuration["ConnectionStrings:Signalr"];
            });
            services.AddDbContext <AnfDbContext>((x, y) =>
            {
                var config = x.GetRequiredService <IConfiguration>();
                y.UseSqlServer(config["ConnectionStrings:anfdb"]);
            }, optionsLifetime: ServiceLifetime.Singleton)
            .AddDbContextPool <AnfDbContext>((x, y) =>
            {
                var config = x.GetRequiredService <IConfiguration>();
                y.UseSqlServer(config["ConnectionStrings:anfdb"]);
            }).AddIdentity <AnfUser, AnfRole>(x =>
            {
                x.Password.RequireDigit           = false;
                x.Password.RequiredUniqueChars    = 0;
                x.Password.RequireLowercase       = false;
                x.Password.RequireNonAlphanumeric = false;
                x.Password.RequireUppercase       = false;
            })
            .AddEntityFrameworkStores <AnfDbContext>();
            services.AddSingleton <IDistributedCache, RedisCache>();
            services.AddOptions <RedisCacheOptions>()
            .Configure(x => x.Configuration = Configuration["ConnectionStrings:CacheConnection"]);
            services.AddResponseCompression();
            services.AddScoped <UserService>();
            services.AddScoped <UserIdentityService>();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("Anf", new OpenApiInfo
                {
                    Version = "v1",
                    Title   = "Anf API"
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
            services.AddMemoryCache();
            services.AddAuthorization();
            services.AddAuthentication(options =>
            {
                options.AddScheme <AnfAuthenticationHandler>(AnfAuthenticationHandler.SchemeName, "default scheme");
                options.DefaultAuthenticateScheme = AnfAuthenticationHandler.SchemeName;
                options.DefaultChallengeScheme    = AnfAuthenticationHandler.SchemeName;
            });

            services.AddScoped <AnfAuthenticationHandler>();
            services.AddScoped <ComicRankService>();
            services.AddScoped <ComicRankSaver>();
            services.AddScoped <BookshelfService>();
            services.AddScoped <HotSearchService>();

            services.AddOptions <BookshelfOptions>();
            services.AddOptions <ComicRankOptions>();
            services.AddOptions <FetchOptions>();
            services.AddOptions <ResourceLockOptions>();
            services.AddFetcherProvider()
            .AddRedisFetcherProvider()
            .AddMssqlResourceFetcher()
            .AddDefaultFetcherProvider();
            services.AddResourceFetcher()
            .AddMssqlResourceFetcher()
            .AddRedisFetcherProvider();
            services.AddScoped <IDbContextTransfer, AnfDbContextTransfer>();
            services.AddRedis();
            services.AddScoped <ReadingManager>();
            AddQuartzAsync(services).GetAwaiter().GetResult();
        }
예제 #5
0
파일: AppGlobal.cs 프로젝트: Cricle/Anf
 public static void Init()
 {
     AppEngine.AddServices();
     AppEngine.Services.AddDefaultEasyComic();
 }
예제 #6
0
 private static void AddCore()
 {
     AppEngine.Services.AddViewModels();
     AppEngine.Services.AddMAUIService();
     AppEngine.AddServices(NetworkAdapterTypes.WebRequest);
 }