Mango.Nop.Plugins/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs

99 lines
4.2 KiB
C#

using AyCode.Core.Extensions;
using Mango.Nop.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Infrastructure;
using Nop.Data;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.AuctionPlugin.Domains.EventConsumers;
using Nop.Plugin.Misc.AuctionPlugin.Hubs;
using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Catalog;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Orders;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc.Routing;
namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
{
public class PluginNopStartup : INopStartup
{
public int Order => 999;
/// <summary>
/// Add and configure any of the middleware
/// </summary>
/// <param name="services">Collection of service descriptors</param>
/// <param name="configuration">Configuration of the application</param>
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new ViewLocationExpander());
});
services.AddSignalR(hubOptions =>
{
hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
});
//register services and interfaces
//IRepository<AuctionBid> _customerBidRepository;
//protected readonly IShortTermCacheManager _shortTermCacheManager;
// protected readonly IStaticCacheManager _staticCacheManager;
services.AddScoped<ILocalizationService, LocalizationService>();
services.AddScoped<ISettingService, SettingService>();
services.AddScoped<AuctionEventConsumer>();
services.AddScoped<IWorkContext, WebWorkContext>();
services.AddScoped<IAnnouncementService, AnnouncementService>();
services.AddScoped<AuctionService>();
services.AddScoped<IProductAttributeService, ProductAttributeService>();
services.AddScoped<UrlHelperFactory>();
services.AddScoped<IActionContextAccessor, ActionContextAccessor>();
services.AddScoped<AuctionDbTable>();
services.AddScoped<ProductToAuctionDbTable>();
services.AddScoped<AuctionBidDbTable>();
services.AddScoped<AuctionDbContext>();
services.AddScoped<MyProductModelFactory>();
services.AddScoped<SignalRMessageHandler>();
services.AddScoped<IOrderService, OrderService>();
services.AddScoped<IOrderProcessingService, OrderProcessingService>();
services.AddScoped<IShoppingCartService, ShoppingCartService>();
services.AddScoped<IStoreContext, WebStoreContext>();
}
/// <summary>
/// Configure the using of added middleware
/// </summary>
/// <param name="application">Builder for configuring an application's request pipeline</param>
public void Configure(IApplicationBuilder application)
{
SerializeObjectExtensions.Options.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
SerializeObjectExtensions.Options.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
SerializeObjectExtensions.Options.NullValueHandling = NullValueHandling.Ignore;
SerializeObjectExtensions.Options.ContractResolver = new CamelCasePropertyNamesContractResolver();
application.UseEndpoints(endpoints =>
{
endpoints.MapHub<AuctionHub>("/auctionhub");
});
application.UseCors(options => {
options.AllowAnyMethod().AllowAnyHeader().AllowCredentials().SetIsOriginAllowed((hosts) => true);
});
}
}
}