|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Microsoft.AspNetCore.Builder; |
| 6 | +using Microsoft.AspNetCore.Hosting; |
| 7 | +using Microsoft.Extensions.Configuration; |
| 8 | +using Microsoft.Extensions.DependencyInjection; |
| 9 | +using Microsoft.Extensions.Logging; |
| 10 | +using DinkToPdf.Contracts; |
| 11 | + |
| 12 | +namespace DinkToPdf.TestWebServer |
| 13 | +{ |
| 14 | + //************************************* IMPORTANT *********************************** |
| 15 | + // Copy native library to root folder of your project. From there .NET Core loads native library when native method is called with P/Invoke. You can find latest version of native library https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4. Select appropriate library for your OS and platform (64 or 32 bit). |
| 16 | + public class Startup |
| 17 | + { |
| 18 | + public Startup(IHostingEnvironment env) |
| 19 | + { |
| 20 | + var builder = new ConfigurationBuilder() |
| 21 | + .SetBasePath(env.ContentRootPath) |
| 22 | + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
| 23 | + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); |
| 24 | + |
| 25 | + if (env.IsEnvironment("Development")) |
| 26 | + { |
| 27 | + // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. |
| 28 | + builder.AddApplicationInsightsSettings(developerMode: true); |
| 29 | + } |
| 30 | + |
| 31 | + builder.AddEnvironmentVariables(); |
| 32 | + Configuration = builder.Build(); |
| 33 | + } |
| 34 | + |
| 35 | + public IConfigurationRoot Configuration { get; } |
| 36 | + |
| 37 | + // This method gets called by the runtime. Use this method to add services to the container |
| 38 | + public void ConfigureServices(IServiceCollection services) |
| 39 | + { |
| 40 | + // Add converter to DI |
| 41 | + services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); |
| 42 | + // Add framework services. |
| 43 | + services.AddApplicationInsightsTelemetry(Configuration); |
| 44 | + |
| 45 | + services.AddMvc(); |
| 46 | + } |
| 47 | + |
| 48 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline |
| 49 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
| 50 | + { |
| 51 | + loggerFactory.AddConsole(Configuration.GetSection("Logging")); |
| 52 | + loggerFactory.AddDebug(); |
| 53 | + |
| 54 | + app.UseApplicationInsightsRequestTelemetry(); |
| 55 | + |
| 56 | + app.UseApplicationInsightsExceptionTelemetry(); |
| 57 | + |
| 58 | + app.UseMvc(); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments