├── .gitattributes ├── .gitignore ├── AutofacDemo ├── AutofacDemo.sln └── AutofacDemo │ ├── AutofacDemo.csproj │ ├── AutofacRootModule.cs │ ├── Controllers │ └── HomeController.cs │ ├── Models │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ ├── CreatedOnDateTimeService.cs │ ├── ICreatedOnDateTimeService.cs │ ├── IScopedService.cs │ ├── ISingletonService.cs │ └── ITransientService.cs │ ├── Startup.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ └── lib │ ├── bootstrap │ ├── LICENSE │ └── dist │ │ ├── css │ │ ├── bootstrap-grid.css │ │ ├── bootstrap-grid.css.map │ │ ├── bootstrap-grid.min.css │ │ ├── bootstrap-grid.min.css.map │ │ ├── bootstrap-reboot.css │ │ ├── bootstrap-reboot.css.map │ │ ├── bootstrap-reboot.min.css │ │ ├── bootstrap-reboot.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ ├── LICENSE.txt │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ ├── LICENSE.md │ └── dist │ │ ├── additional-methods.js │ │ ├── additional-methods.min.js │ │ ├── jquery.validate.js │ │ └── jquery.validate.min.js │ └── jquery │ ├── LICENSE.txt │ └── dist │ ├── jquery.js │ ├── jquery.min.js │ └── jquery.min.map ├── BenchmarkDotNetSample ├── BenchmarkDotNetSample.sln └── BenchmarkDotNetSample │ ├── BenchmarkDotNetSample.csproj │ ├── MyBenchmarks.cs │ ├── Program.cs │ └── StringCompareUtil.cs ├── ConsoleAppConfigDemo ├── ConsoleAppConfigDemo.sln └── ConsoleAppConfigDemo │ ├── ConsoleAppConfigDemo.csproj │ ├── Program.cs │ ├── Worker.cs │ └── appsettings.json ├── CustomConfigProviderExample ├── CustomConfigProviderExample.sln └── CustomConfigProviderExample │ ├── Controllers │ └── HomeController.cs │ ├── CustomConfigProvider │ ├── ConfigurationSetting.cs │ ├── CustomConfigProviderExtensions.cs │ ├── CustomConfigurationProvider.cs │ ├── CustomConfigurationProviderDbContext.cs │ └── CustomConfigurationSource.cs │ ├── CustomConfigProviderExample.csproj │ ├── Models │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ └── lib │ ├── bootstrap │ ├── LICENSE │ └── dist │ │ ├── css │ │ ├── bootstrap-grid.css │ │ ├── bootstrap-grid.css.map │ │ ├── bootstrap-grid.min.css │ │ ├── bootstrap-grid.min.css.map │ │ ├── bootstrap-reboot.css │ │ ├── bootstrap-reboot.css.map │ │ ├── bootstrap-reboot.min.css │ │ ├── bootstrap-reboot.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ ├── LICENSE.txt │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ ├── LICENSE.md │ └── dist │ │ ├── additional-methods.js │ │ ├── additional-methods.min.js │ │ ├── jquery.validate.js │ │ └── jquery.validate.min.js │ └── jquery │ ├── LICENSE.txt │ └── dist │ ├── jquery.js │ ├── jquery.min.js │ └── jquery.min.map ├── DIConsoleDemo ├── DIConsoleDemo.sln └── DIConsoleDemo │ ├── DIConsoleDemo.csproj │ ├── GetCreatedTime.cs │ ├── GetCreatedTimeInvoker.cs │ ├── IGetCreatedTime.cs │ ├── IScopedGetCreatedTime.cs │ ├── ISingletonGetCreatedTime.cs │ ├── ITransientGetCreatedTime.cs │ └── Program.cs ├── DelayedInstantiationDemo ├── DelayedInstantiationDemo.sln └── DelayedInstantiationDemo │ ├── Controllers │ └── HomeController.cs │ ├── DelayedInstantiationDemo.csproj │ ├── LazyInstance.cs │ ├── Models │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ ├── CreatedOnDateTimeService.cs │ └── ICreatedOnDateTimeService.cs │ ├── Startup.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ └── lib │ ├── bootstrap │ ├── LICENSE │ └── dist │ │ ├── css │ │ ├── bootstrap-grid.css │ │ ├── bootstrap-grid.css.map │ │ ├── bootstrap-grid.min.css │ │ ├── bootstrap-grid.min.css.map │ │ ├── bootstrap-reboot.css │ │ ├── bootstrap-reboot.css.map │ │ ├── bootstrap-reboot.min.css │ │ ├── bootstrap-reboot.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ ├── LICENSE.txt │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ ├── LICENSE.md │ └── dist │ │ ├── additional-methods.js │ │ ├── additional-methods.min.js │ │ ├── jquery.validate.js │ │ └── jquery.validate.min.js │ └── jquery │ ├── LICENSE.txt │ └── dist │ ├── jquery.js │ ├── jquery.min.js │ └── jquery.min.map ├── EFCoreBlogDemo ├── Blog.Api │ ├── Blog.Api.csproj │ ├── BlogMapperProfile.cs │ ├── Controllers │ │ ├── CategoriesController.cs │ │ ├── PostsController.cs │ │ ├── TagsController.cs │ │ └── WeatherForecastController.cs │ ├── Models │ │ ├── BaseModel.cs │ │ ├── CategoryModel.cs │ │ ├── CommentModel.cs │ │ ├── PostModel.cs │ │ └── TagModel.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── Blog.Business.Contracts │ ├── BaseBusiness.cs │ ├── Blog.Business.Contracts.csproj │ ├── IBaseBusiness.cs │ ├── ICategoriesBusiness.cs │ ├── IPostsBusiness.cs │ └── ITagsBusiness.cs ├── Blog.Business │ ├── Blog.Business.csproj │ ├── CategoriesBusiness.cs │ ├── PostsBusiness.cs │ └── TagsBusiness.cs ├── Blog.Data.Contracts │ ├── BaseRepository.cs │ ├── Blog.Data.Contracts.csproj │ ├── IBaseRepository.cs │ ├── ICategoriesRepository.cs │ ├── IPostsRepository.cs │ ├── ITagsRepository.cs │ └── Specifications │ │ ├── BaseSpecifications.cs │ │ ├── CompositeSpecification.cs │ │ ├── IBaseSpecifications.cs │ │ ├── PostRelatedDataSpecifications.cs │ │ └── SpecificationEvaluator.cs ├── Blog.Data.EF │ ├── BaseEntity.cs │ ├── Blog.Data.EF.csproj │ ├── BlogContext.cs │ ├── DesignTimeBlogContextFactory.cs │ ├── Entities │ │ ├── Category.cs │ │ ├── Comment.cs │ │ ├── Post.cs │ │ ├── PostCategories.cs │ │ ├── PostTags.cs │ │ ├── Tag.cs │ │ └── User.cs │ ├── Migrations │ │ ├── 20210703214710_InitialCreate.Designer.cs │ │ ├── 20210703214710_InitialCreate.cs │ │ └── BlogContextModelSnapshot.cs │ └── ef-core-commands.bat ├── Blog.Data.Tests │ ├── Blog.Data.Tests.csproj │ └── PostsRepositoryTests.cs ├── Blog.Data │ ├── Blog.Data.csproj │ ├── CategoriesRepository.cs │ ├── PostsRepository.cs │ └── TagsRepository.cs └── EFCoreBlogDemo.sln ├── EFCoreConcepts ├── EFCoreConcepts.sln └── University.Data.EF.Models │ ├── DesignTimeUniversityContextFactory.cs │ ├── Migrations │ ├── 20210620130352_InitialCreate.Designer.cs │ ├── 20210620130352_InitialCreate.cs │ └── UniversityContextModelSnapshot.cs │ ├── Student.cs │ ├── StudentEntityTypeConfiguration.cs │ ├── University.Data.EF.Models.csproj │ └── UniversityContext.cs ├── EFCoreDeleteExamples ├── DeleteExamples.Data.EF │ ├── DeleteExamples.Data.EF.csproj │ ├── DesignTimeUniversityContextFactory.cs │ ├── Entities │ │ ├── Author.cs │ │ ├── Book.cs │ │ ├── Country.cs │ │ ├── CountryLanguage.cs │ │ ├── Language.cs │ │ ├── Student.cs │ │ └── Teacher.cs │ ├── Migrations │ │ ├── 20211203221510_InitialCreate.Designer.cs │ │ ├── 20211203221510_InitialCreate.cs │ │ └── UniversityContextModelSnapshot.cs │ ├── UniversityContext.cs │ └── ef-core-commands.bat ├── DeleteExamples.sln └── DeleteExamples │ ├── DeleteExamples.csproj │ ├── ManyToManyHelper.cs │ ├── OneToManyHelper.cs │ ├── OneToOneHelper.cs │ └── Program.cs ├── EFCoreFunctionsDemo ├── EFCoreFunctionsDemo.Data.EF │ ├── DesignTimeUniversityContextFactory.cs │ ├── EFCoreFunctionsDemo.Data.EF.csproj │ ├── FunctionMappingUtil.cs │ ├── Migrations │ │ ├── 20210721205433_InitialCreate.Designer.cs │ │ ├── 20210721205433_InitialCreate.cs │ │ └── UniversityContextModelSnapshot.cs │ ├── Student.cs │ ├── UniversityContext.cs │ └── ef-core-commands.bat ├── EFCoreFunctionsDemo.sln └── EFCoreFunctionsDemo │ ├── EFCoreFunctionsDemo.csproj │ └── Program.cs ├── EFCoreGlobalFiltersDemo ├── EFCoreGlobalFiltersDemo.Data.EF │ ├── DesignTimeUniversityContextFactory.cs │ ├── EFCoreGlobalFiltersDemo.Data.EF.csproj │ ├── FunctionMappingUtil.cs │ ├── Migrations │ │ ├── 20210722180825_InitialCreate.Designer.cs │ │ ├── 20210722180825_InitialCreate.cs │ │ └── UniversityContextModelSnapshot.cs │ ├── Student.cs │ ├── UniversityContext.cs │ └── ef-core-commands.bat ├── EFCoreGlobalFiltersDemo.sln └── EFCoreGlobalFiltersDemo │ ├── EFCoreGlobalFiltersDemo.csproj │ └── Program.cs ├── EFCoreInterceptorsDemo ├── EFCoreInterceptorsDemo.Data.EF │ ├── DemoDbCommandInterceptor.cs │ ├── DesignTimeUniversityContextFactory.cs │ ├── EFCoreInterceptorsDemo.Data.EF.csproj │ ├── Migrations │ │ ├── 20210717165953_InitialCreate.Designer.cs │ │ ├── 20210717165953_InitialCreate.cs │ │ └── UniversityContextModelSnapshot.cs │ ├── Student.cs │ ├── UniversityContext.cs │ └── ef-core-commands.bat ├── EFCoreInterceptorsDemo.sln └── EFCoreInterceptorsDemo │ ├── EFCoreInterceptorsDemo.csproj │ └── Program.cs ├── EFCoreRelationships ├── EFCoreRelationships.sln └── University.Data.EF.Models │ ├── Course.cs │ ├── DesignTimeUniversityContextFactory.cs │ ├── Migrations │ ├── 20210622202712_InitialCreate.Designer.cs │ ├── 20210622202712_InitialCreate.cs │ └── UniversityContextModelSnapshot.cs │ ├── Student.cs │ ├── StudentEntityTypeConfiguration.cs │ ├── University.Data.EF.Models.csproj │ ├── UniversityContext.cs │ └── ef-core-commands.bat ├── EventsDemo ├── EventsDemo.Data.EF │ ├── DesignTimeUniversityContextFactory.cs │ ├── EventsDemo.Data.EF.csproj │ ├── Migrations │ │ ├── 20210716172519_InitialCreate.Designer.cs │ │ ├── 20210716172519_InitialCreate.cs │ │ └── UniversityContextModelSnapshot.cs │ ├── Student.cs │ ├── UniversityContext.cs │ └── ef-core-commands.bat ├── EventsDemo.sln └── EventsDemoConsole │ ├── EventsDemoConsole.csproj │ └── Program.cs ├── ExceptionHandlingDemo ├── ExceptionHandlingDemo.sln └── WebApiDemo │ ├── Controllers │ ├── ErrorController.cs │ └── GetValueController.cs │ ├── CustomExceptionFilterAttribute.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiDemo.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── HttpClientDemo-Typed ├── HttpClientDemo.sln └── HttpClientDemo │ ├── Controllers │ └── HomeController.cs │ ├── GitHubApionsumer.cs │ ├── GitHubRepo.cs │ ├── HttpClientDemo.csproj │ ├── Models │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ └── lib │ ├── bootstrap │ ├── LICENSE │ └── dist │ │ ├── css │ │ ├── bootstrap-grid.css │ │ ├── bootstrap-grid.css.map │ │ ├── bootstrap-grid.min.css │ │ ├── bootstrap-grid.min.css.map │ │ ├── bootstrap-reboot.css │ │ ├── bootstrap-reboot.css.map │ │ ├── bootstrap-reboot.min.css │ │ ├── bootstrap-reboot.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ ├── LICENSE.txt │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ ├── LICENSE.md │ └── dist │ │ ├── additional-methods.js │ │ ├── additional-methods.min.js │ │ ├── jquery.validate.js │ │ └── jquery.validate.min.js │ └── jquery │ ├── LICENSE.txt │ └── dist │ ├── jquery.js │ ├── jquery.min.js │ └── jquery.min.map ├── LICENSE ├── LoggingExamples ├── HostBasedConsoleApp │ ├── HostBasedConsoleApp.csproj │ ├── Program.cs │ └── Worker.cs ├── LoggingExamples.sln ├── NonHostConsole │ ├── NonHostConsole.csproj │ └── Program.cs └── WebAppLoggingExample │ ├── Controllers │ └── HomeController.cs │ ├── Models │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── WebAppLoggingExample.csproj │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ └── lib │ ├── bootstrap │ ├── LICENSE │ └── dist │ │ ├── css │ │ ├── bootstrap-grid.css │ │ ├── bootstrap-grid.css.map │ │ ├── bootstrap-grid.min.css │ │ ├── bootstrap-grid.min.css.map │ │ ├── bootstrap-reboot.css │ │ ├── bootstrap-reboot.css.map │ │ ├── bootstrap-reboot.min.css │ │ ├── bootstrap-reboot.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ ├── LICENSE.txt │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ ├── LICENSE.md │ └── dist │ │ ├── additional-methods.js │ │ ├── additional-methods.min.js │ │ ├── jquery.validate.js │ │ └── jquery.validate.min.js │ └── jquery │ ├── LICENSE.txt │ └── dist │ ├── jquery.js │ ├── jquery.min.js │ └── jquery.min.map ├── OptionsExample ├── OptionsExample.sln └── OptionsExample │ ├── Configurations │ └── MailFeature.cs │ ├── Controllers │ └── HomeController.cs │ ├── Models │ └── ErrorViewModel.cs │ ├── OptionsExample.csproj │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ └── lib │ ├── bootstrap │ ├── LICENSE │ └── dist │ │ ├── css │ │ ├── bootstrap-grid.css │ │ ├── bootstrap-grid.css.map │ │ ├── bootstrap-grid.min.css │ │ ├── bootstrap-grid.min.css.map │ │ ├── bootstrap-reboot.css │ │ ├── bootstrap-reboot.css.map │ │ ├── bootstrap-reboot.min.css │ │ ├── bootstrap-reboot.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ ├── LICENSE.txt │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ ├── LICENSE.md │ └── dist │ │ ├── additional-methods.js │ │ ├── additional-methods.min.js │ │ ├── jquery.validate.js │ │ └── jquery.validate.min.js │ └── jquery │ ├── LICENSE.txt │ └── dist │ ├── jquery.js │ ├── jquery.min.js │ └── jquery.min.map ├── PassByReferenceDemo ├── ParametersDemo │ ├── ParametersDemo.csproj │ ├── Program.cs │ ├── ReferenceTypeDemo.cs │ └── ValueTypeDemo.cs └── PassByReferenceDemo.sln ├── README.md ├── RecordExample ├── RecordExample.sln └── RecordExample │ ├── Program.cs │ └── RecordExample.csproj ├── WebApiAutoMapperDemo ├── WebApiAutoMapperDemo.sln └── WebApiAutoMapperDemo │ ├── ApiMappingProfile.cs │ ├── Controllers │ └── WeatherForecastController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Source.cs │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiAutoMapperDemo.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── WebApiDistributedMemoryCache ├── WebApiDistributedMemoryCache.sln └── WebApiDistributedMemoryCache │ ├── Controllers │ └── WeatherForecastController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiDistributedMemoryCache.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── WebApiDistributedSqlCache ├── WebApiDistributedSqlCache.sln └── WebApiDistributedSqlCache │ ├── Controllers │ └── WeatherForecastController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiDistributedSqlCache.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── WebApiInMemoryCaching ├── WebApiInMemoryCaching.sln └── WebApiInMemoryCaching │ ├── Controllers │ └── WeatherForecastController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiInMemoryCaching.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── WebApiModelValidationDemo ├── WebApiModelValidationDemo.sln └── WebApiModelValidationDemo │ ├── Controllers │ ├── ValuesController.cs │ └── WeatherForecastController.cs │ ├── Models │ └── Employee.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiModelValidationDemo.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── WebApiOrderedFilterDemo ├── WebApiOrderedFilterDemo.sln └── WebApiOrderedFilterDemo │ ├── Controllers │ └── WeatherForecastController.cs │ ├── CustomActionFilterAttribute.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiOrderedFilterDemo.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── WebApiResponseCachingDemo ├── WebApiResponseCachingDemo.sln └── WebApiResponseCachingDemo │ ├── Controllers │ ├── ValuesController.cs │ └── WeatherForecastController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── WebApiResponseCachingDemo.csproj │ ├── appsettings.Development.json │ └── appsettings.json └── WebApiResponseFormatters ├── WebApiFormatters ├── Controllers │ └── WeatherForecastController.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── WeatherForecast.cs ├── WebApiFormatters.csproj ├── appsettings.Development.json └── appsettings.json └── WebApiResponseFormatters.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31205.134 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutofacDemo", "AutofacDemo\AutofacDemo.csproj", "{DB8B5EBD-F5C7-45E4-9D4F-642496FD3EE8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DB8B5EBD-F5C7-45E4-9D4F-642496FD3EE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DB8B5EBD-F5C7-45E4-9D4F-642496FD3EE8}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DB8B5EBD-F5C7-45E4-9D4F-642496FD3EE8}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DB8B5EBD-F5C7-45E4-9D4F-642496FD3EE8}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F6B1C3E0-B55A-4251-ABE3-1B5E233565C3} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/AutofacDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/AutofacRootModule.cs: -------------------------------------------------------------------------------- 1 |  2 | using Autofac; 3 | 4 | using AutofacDemo.Services; 5 | 6 | namespace AutofacDemo 7 | { 8 | public class AutofacRootModule : Module 9 | { 10 | protected override void Load(ContainerBuilder builder) 11 | { 12 | // The generic ILogger service was added to the ServiceCollection by ASP.NET Core. 13 | // It was then registered with Autofac using the Populate method. All of this starts 14 | // with the services.AddAutofac() that happens in Program and registers Autofac 15 | // as the service provider. 16 | builder.RegisterType().As().SingleInstance(); 17 | builder.RegisterType().As().InstancePerLifetimeScope(); 18 | builder.RegisterType().As().InstancePerDependency(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AutofacDemo.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Autofac.Extensions.DependencyInjection; 7 | 8 | using Microsoft.AspNetCore.Hosting; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.Hosting; 11 | using Microsoft.Extensions.Logging; 12 | 13 | namespace AutofacDemo 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args) 20 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 21 | .Build().Run(); 22 | } 23 | 24 | public static IHostBuilder CreateHostBuilder(string[] args) => 25 | Host.CreateDefaultBuilder(args) 26 | .ConfigureWebHostDefaults(webBuilder => 27 | { 28 | webBuilder.UseStartup(); 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:52462", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development", 16 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" 17 | } 18 | }, 19 | "AutofacDemo": { 20 | "commandName": "Project", 21 | "dotnetRunMessages": "true", 22 | "launchBrowser": true, 23 | "applicationUrl": "http://localhost:5000", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development", 26 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Services/CreatedOnDateTimeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AutofacDemo.Services 4 | { 5 | public class CreatedOnDateTimeService : ISingletonService, IScopedService, ITransientService 6 | { 7 | private readonly DateTime createdOn; 8 | 9 | public CreatedOnDateTimeService() 10 | { 11 | createdOn = DateTime.Now.AddHours(-4); 12 | } 13 | 14 | public DateTime CreatedOn { get => createdOn; set => throw new NotImplementedException(); } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Services/ICreatedOnDateTimeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AutofacDemo.Services 4 | { 5 | public interface ICreatedOnDateTimeService 6 | { 7 | public DateTime CreatedOn { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Services/IScopedService.cs: -------------------------------------------------------------------------------- 1 | namespace AutofacDemo.Services 2 | { 3 | public interface IScopedService: ICreatedOnDateTimeService 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Services/ISingletonService.cs: -------------------------------------------------------------------------------- 1 | namespace AutofacDemo.Services 2 | { 3 | public interface ISingletonService: ICreatedOnDateTimeService 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Services/ITransientService.cs: -------------------------------------------------------------------------------- 1 | namespace AutofacDemo.Services 2 | { 3 | public interface ITransientService: ICreatedOnDateTimeService 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome

7 |

Learn about Autofac integration with ASP .NET Core Web Apps

8 |
9 |
10 | Created On Times (Transient and Scoped is same in this case, can you guess why ?) 11 |
12 |
    13 |
  • Singleton.CreatedOn: @ViewData["SingletonCreatedOn"]
  • 14 |
  • Scoped.CreatedOn: @ViewData["ScopedCreatedOn"]
  • 15 |
  • Transient.CreatedOn: @ViewData["TransientCreatedOn"]
  • 16 |
17 |
18 |
19 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using AutofacDemo 2 | @using AutofacDemo.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manoj-choudhari-git/dotnet-on-thecodeblogger/12eb7fcbad283d54c391edc440cc99c4ef549921/AutofacDemo/AutofacDemo/wwwroot/favicon.ico -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /BenchmarkDotNetSample/BenchmarkDotNetSample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32421.90 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNetSample", "BenchmarkDotNetSample\BenchmarkDotNetSample.csproj", "{41BA7FA1-DDBD-49FF-A94F-B3605A40A15C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {41BA7FA1-DDBD-49FF-A94F-B3605A40A15C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {41BA7FA1-DDBD-49FF-A94F-B3605A40A15C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {41BA7FA1-DDBD-49FF-A94F-B3605A40A15C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {41BA7FA1-DDBD-49FF-A94F-B3605A40A15C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {8D15EAD1-9B06-4CAF-8A58-6491C57FAD67} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /BenchmarkDotNetSample/BenchmarkDotNetSample/BenchmarkDotNetSample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /BenchmarkDotNetSample/BenchmarkDotNetSample/MyBenchmarks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography; 3 | using BenchmarkDotNet.Attributes; 4 | using BenchmarkDotNet.Running; 5 | 6 | namespace BenchmarkDotNetSample 7 | { 8 | public class MyBenchmarks 9 | { 10 | private const int N = 10000; 11 | private readonly byte[] data; 12 | 13 | private readonly SHA256 sha256 = SHA256.Create(); 14 | private readonly MD5 md5 = MD5.Create(); 15 | 16 | public MyBenchmarks() 17 | { 18 | data = new byte[N]; 19 | new Random(42).NextBytes(data); 20 | } 21 | 22 | [Benchmark] 23 | public byte[] Sha256() => sha256.ComputeHash(data); 24 | 25 | [Benchmark] 26 | public byte[] Md5() => md5.ComputeHash(data); 27 | } 28 | 29 | //public class Program 30 | //{ 31 | // //public static void Main(string[] args) 32 | // //{ 33 | // // var summary = BenchmarkRunner.Run(typeof(Program).Assembly); 34 | // //} 35 | //} 36 | } 37 | -------------------------------------------------------------------------------- /BenchmarkDotNetSample/BenchmarkDotNetSample/Program.cs: -------------------------------------------------------------------------------- 1 | // See https://aka.ms/new-console-template for more information 2 | 3 | using BenchmarkDotNet.Running; 4 | using BenchmarkDotNetSample; 5 | using System.Diagnostics; 6 | 7 | Stopwatch sw = Stopwatch.StartNew(); 8 | 9 | var summary = BenchmarkRunner.Run(); 10 | 11 | sw.Stop(); 12 | Console.WriteLine("================================================================="); 13 | Console.WriteLine($"Total Elapsed Milliseconds: {sw.ElapsedMilliseconds}"); 14 | Console.WriteLine("================================================================="); 15 | 16 | 17 | 18 | //sw.Start(); 19 | //var summaries = BenchmarkRunner.Run(); 20 | 21 | 22 | //Console.WriteLine("================================================================="); 23 | //Console.WriteLine($"Total Elapsed Milliseconds: {sw.ElapsedMilliseconds}"); 24 | //Console.WriteLine("================================================================="); 25 | 26 | -------------------------------------------------------------------------------- /ConsoleAppConfigDemo/ConsoleAppConfigDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31205.134 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppConfigDemo", "ConsoleAppConfigDemo\ConsoleAppConfigDemo.csproj", "{A060FAA9-B4E2-4D16-B1C3-F04E8891E0FB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {A060FAA9-B4E2-4D16-B1C3-F04E8891E0FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {A060FAA9-B4E2-4D16-B1C3-F04E8891E0FB}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {A060FAA9-B4E2-4D16-B1C3-F04E8891E0FB}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {A060FAA9-B4E2-4D16-B1C3-F04E8891E0FB}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {CB80F41E-6ED0-4EAB-BF5D-157245A4EBBF} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /ConsoleAppConfigDemo/ConsoleAppConfigDemo/ConsoleAppConfigDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Always 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ConsoleAppConfigDemo/ConsoleAppConfigDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.Hosting; 6 | 7 | namespace ConsoleAppConfigDemo 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | var host = CreateDefaultBuilder().Build(); 14 | using IServiceScope serviceScope = host.Services.CreateScope(); 15 | IServiceProvider provider = serviceScope.ServiceProvider; 16 | var workerInstance = provider.GetRequiredService(); 17 | workerInstance.DoWork(); 18 | host.Run(); 19 | } 20 | 21 | static IHostBuilder CreateDefaultBuilder() 22 | { 23 | return Host.CreateDefaultBuilder() 24 | .ConfigureAppConfiguration(app => 25 | { 26 | app.AddJsonFile("appsettings.json"); 27 | }) 28 | .ConfigureServices(services => 29 | { 30 | services.AddSingleton(); 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ConsoleAppConfigDemo/ConsoleAppConfigDemo/Worker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace ConsoleAppConfigDemo 7 | { 8 | internal class Worker 9 | { 10 | private readonly IConfiguration configuration; 11 | 12 | public Worker(IConfiguration configuration) 13 | { 14 | this.configuration = configuration; 15 | } 16 | 17 | public void DoWork() 18 | { 19 | var keyValuePairs = configuration.AsEnumerable().ToList(); 20 | Console.ForegroundColor = ConsoleColor.Green; 21 | Console.WriteLine("=============================================="); 22 | Console.WriteLine("Configurations..."); 23 | Console.WriteLine("=============================================="); 24 | foreach (var pair in keyValuePairs) 25 | { 26 | Console.WriteLine($"{pair.Key} - {pair.Value}"); 27 | } 28 | Console.WriteLine("=============================================="); 29 | Console.ResetColor(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /ConsoleAppConfigDemo/ConsoleAppConfigDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "SqlConnectionString": "SomeConnectionString" 4 | }, 5 | "Mode": "Dev" 6 | } 7 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31112.23 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomConfigProviderExample", "CustomConfigProviderExample\CustomConfigProviderExample.csproj", "{83FD30D0-2956-4FA0-9336-A433168B8B75}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {83FD30D0-2956-4FA0-9336-A433168B8B75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {83FD30D0-2956-4FA0-9336-A433168B8B75}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {83FD30D0-2956-4FA0-9336-A433168B8B75}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {83FD30D0-2956-4FA0-9336-A433168B8B75}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {65B16843-8CEE-441C-A7BC-22C4AEDC5508} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/CustomConfigProvider/ConfigurationSetting.cs: -------------------------------------------------------------------------------- 1 | namespace CustomConfigProviderExample.CustomConfigProvider 2 | { 3 | public class ConfigurationSetting 4 | { 5 | public int Id { get; set; } 6 | 7 | public string Key { get; set; } 8 | 9 | public string Value { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/CustomConfigProvider/CustomConfigProviderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace CustomConfigProviderExample.CustomConfigProvider 7 | { 8 | public static class CustomConfigProviderExtensions 9 | { 10 | public static IConfigurationBuilder AddCustomDatabaseConfiguration( 11 | this IConfigurationBuilder builder, Action optionsAction) 12 | { 13 | return builder.Add(new CustomConfigurationSource(optionsAction)); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/CustomConfigProvider/CustomConfigurationProviderDbContext.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace CustomConfigProviderExample.CustomConfigProvider 5 | { 6 | public class CustomConfigurationProviderDbContext: DbContext 7 | { 8 | public CustomConfigurationProviderDbContext(DbContextOptions options) : base(options) 9 | { 10 | } 11 | 12 | public DbSet ConfigurationSetting { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/CustomConfigProvider/CustomConfigurationSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace CustomConfigProviderExample.CustomConfigProvider 7 | { 8 | public class CustomConfigurationSource : IConfigurationSource 9 | { 10 | private readonly Action _optionsAction; 11 | 12 | public CustomConfigurationSource(Action optionsAction) 13 | { 14 | _optionsAction = optionsAction; 15 | } 16 | 17 | public IConfigurationProvider Build(IConfigurationBuilder builder) 18 | { 19 | return new CustomConfigurationProvider(_optionsAction); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/CustomConfigProviderExample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CustomConfigProviderExample.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using CustomConfigProviderExample.CustomConfigProvider; 7 | 8 | using Microsoft.AspNetCore.Hosting; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.Hosting; 11 | using Microsoft.Extensions.Logging; 12 | using Microsoft.EntityFrameworkCore; 13 | 14 | namespace CustomConfigProviderExample 15 | { 16 | public class Program 17 | { 18 | public static void Main(string[] args) 19 | { 20 | CreateHostBuilder(args).Build().Run(); 21 | } 22 | 23 | public static IHostBuilder CreateHostBuilder(string[] args) => 24 | Host.CreateDefaultBuilder(args) 25 | .ConfigureAppConfiguration((hostingContext, config) => 26 | { 27 | config.AddCustomDatabaseConfiguration(options => options.UseInMemoryDatabase("InMemoryDb")); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:27132", 7 | "sslPort": 44340 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "CustomConfigProviderExample": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome at @ViewData["Mode"]

7 |

Learn about building Web apps with ASP.NET Core.

8 |
9 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using CustomConfigProviderExample 2 | @using CustomConfigProviderExample.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Mode": "default", 3 | "MailFeature": [ 4 | { 5 | "Type": "Marketing", 6 | "From": "marketing@company.com", 7 | "Subject": "Do you know about the latest offer?" 8 | }, 9 | { 10 | "Type": "AccountVerification", 11 | "From": "users@company.com", 12 | "Subject": "Please verify the account by clicking on link." 13 | }, 14 | { 15 | "Type": "OrderPlaced", 16 | "From": "orders@company.com", 17 | "Subject": "Please verify the account by clicking on link." 18 | } 19 | ], 20 | "Logging": { 21 | "LogLevel": { 22 | "Default": "Information", 23 | "Microsoft": "Warning", 24 | "Microsoft.Hosting.Lifetime": "Information" 25 | } 26 | }, 27 | "AllowedHosts": "*" 28 | } 29 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manoj-choudhari-git/dotnet-on-thecodeblogger/12eb7fcbad283d54c391edc440cc99c4ef549921/CustomConfigProviderExample/CustomConfigProviderExample/wwwroot/favicon.ico -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /CustomConfigProviderExample/CustomConfigProviderExample/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31112.23 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DIConsoleDemo", "DIConsoleDemo\DIConsoleDemo.csproj", "{B9A4C7EB-CCAE-40EB-A100-F3CAE73325ED}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B9A4C7EB-CCAE-40EB-A100-F3CAE73325ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B9A4C7EB-CCAE-40EB-A100-F3CAE73325ED}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B9A4C7EB-CCAE-40EB-A100-F3CAE73325ED}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B9A4C7EB-CCAE-40EB-A100-F3CAE73325ED}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {9D2BFA0F-7837-4BEB-83DF-FC0483F6A212} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/DIConsoleDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/GetCreatedTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DIConsoleDemo 8 | { 9 | public class GetCreatedTimeImplementation : ITransientGetCreatedTime, 10 | IScopedGetCreatedTime, 11 | ISingletonGetCreatedTime 12 | { 13 | private readonly DateTime createdOn; 14 | 15 | public GetCreatedTimeImplementation() 16 | { 17 | this.createdOn = DateTime.Now; 18 | } 19 | public DateTime GetCreatedTime() 20 | { 21 | return this.createdOn.AddHours(-6); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/GetCreatedTimeInvoker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DIConsoleDemo 8 | { 9 | class GetCreatedTimeInvoker 10 | { 11 | private readonly ISingletonGetCreatedTime singleton; 12 | private readonly IScopedGetCreatedTime scoped; 13 | private readonly ITransientGetCreatedTime transient; 14 | 15 | public GetCreatedTimeInvoker(ISingletonGetCreatedTime singleton, 16 | IScopedGetCreatedTime scoped, ITransientGetCreatedTime transient) 17 | { 18 | this.singleton = singleton; 19 | this.scoped = scoped; 20 | this.transient = transient; 21 | } 22 | 23 | public void Invoke() 24 | { 25 | Console.WriteLine($"Singleton Response: {singleton.GetCreatedTime():MM/dd/yyyy hh:mm:ss.fff tt}, Stays the same."); 26 | Console.WriteLine($"Scoped Response: {scoped.GetCreatedTime():MM/dd/yyyy hh:mm:ss.fff tt}, Changes only if scope is changed"); 27 | Console.WriteLine($"Transient Response: {transient.GetCreatedTime():MM/dd/yyyy hh:mm:ss.fff tt}, Changes everytime this method is invoked"); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/IGetCreatedTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DIConsoleDemo 8 | { 9 | interface IGetCreatedTime 10 | { 11 | DateTime GetCreatedTime(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/IScopedGetCreatedTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DIConsoleDemo 8 | { 9 | interface IScopedGetCreatedTime : IGetCreatedTime 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/ISingletonGetCreatedTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DIConsoleDemo 8 | { 9 | interface ISingletonGetCreatedTime : IGetCreatedTime 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DIConsoleDemo/DIConsoleDemo/ITransientGetCreatedTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DIConsoleDemo 8 | { 9 | interface ITransientGetCreatedTime : IGetCreatedTime 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31205.134 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelayedInstantiationDemo", "DelayedInstantiationDemo\DelayedInstantiationDemo.csproj", "{2B8F5B53-2B54-4B4E-AA48-7856397F9690}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2B8F5B53-2B54-4B4E-AA48-7856397F9690}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {2B8F5B53-2B54-4B4E-AA48-7856397F9690}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {2B8F5B53-2B54-4B4E-AA48-7856397F9690}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {2B8F5B53-2B54-4B4E-AA48-7856397F9690}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {5781B6D7-0746-4763-AEE5-E7A87BF7C481} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/DelayedInstantiationDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/LazyInstance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace DelayedInstantiationDemo 6 | { 7 | public class LazyInstance: Lazy 8 | { 9 | public LazyInstance(IServiceProvider serviceProvider) 10 | : base(() => serviceProvider.GetRequiredService()) 11 | { 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DelayedInstantiationDemo.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace DelayedInstantiationDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:3802", 7 | "sslPort": 44304 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development", 16 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" 17 | } 18 | }, 19 | "DelayedInstantiationDemo": { 20 | "commandName": "Project", 21 | "dotnetRunMessages": "true", 22 | "launchBrowser": true, 23 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development", 26 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Services/CreatedOnDateTimeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AutofacDemo.Services 4 | { 5 | public class CreatedOnDateTimeService : ICreatedOnDateTimeService 6 | { 7 | private readonly DateTime createdOn; 8 | 9 | public CreatedOnDateTimeService() 10 | { 11 | createdOn = DateTime.Now; 12 | } 13 | 14 | public DateTime CreatedOn { get => createdOn; set => throw new NotImplementedException(); } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Services/ICreatedOnDateTimeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AutofacDemo.Services 4 | { 5 | public interface ICreatedOnDateTimeService 6 | { 7 | public DateTime CreatedOn { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome

7 |

Learn about delayed instantiation with .NET dependency injection

8 |
9 |
10 | Created On Time 11 |
12 |
    13 |
  • Dependency.IsValueCreated: @ViewData["IsValueCreated"]
  • 14 |
  • Dependency.Value.CreatedOn: @ViewData["CreatedOn"]
  • 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using DelayedInstantiationDemo 2 | @using DelayedInstantiationDemo.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manoj-choudhari-git/dotnet-on-thecodeblogger/12eb7fcbad283d54c391edc440cc99c4ef549921/DelayedInstantiationDemo/DelayedInstantiationDemo/wwwroot/favicon.ico -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /DelayedInstantiationDemo/DelayedInstantiationDemo/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Blog.Api.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/BlogMapperProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using AutoMapper; 7 | 8 | using Blog.Api.Models; 9 | using Blog.Data.EF.Entities; 10 | 11 | namespace Blog.Api 12 | { 13 | public class BlogMapperProfile : Profile 14 | { 15 | public BlogMapperProfile() 16 | { 17 | CreateMap().ReverseMap(); 18 | CreateMap().ReverseMap(); 19 | CreateMap().ReverseMap(); 20 | CreateMap() 21 | .ForMember(m => m.PostCategories, opt => opt.Ignore()) 22 | .ForMember(m => m.PostTags, opt => opt.Ignore()) 23 | .ForMember(m => m.Comments, opt => opt.Ignore()) 24 | .ReverseMap(); 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Models/BaseModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Blog.Api.Models 7 | { 8 | public class BaseModel 9 | { 10 | public int Id { get; set; } 11 | public bool IsPublished { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Models/CategoryModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Blog.Api.Models 7 | { 8 | public class CategoryModel : BaseModel 9 | { 10 | public string Title { get; set; } 11 | public string Description { get; set; } 12 | public string Slug { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Models/CommentModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Blog.Data.EF.Entities; 7 | using Blog.Data.EF; 8 | 9 | namespace Blog.Api.Models 10 | { 11 | public class CommentModel : BaseModel 12 | { 13 | public string CommentContents { get; set; } 14 | 15 | public string PostedBy { get; set; } 16 | 17 | public CommentModel Parent { get; set; } 18 | 19 | public PostModel ParentPost { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Models/PostModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Blog.Data.EF.Entities; 7 | 8 | namespace Blog.Api.Models 9 | { 10 | public class PostModel : BaseModel 11 | { 12 | public string Title { get; set; } 13 | public string Slug { get; set; } 14 | public string Summary { get; set; } 15 | public string PostContents { get; set; } 16 | public List PostTags { get; set; } 17 | public List PostCategories { get; set; } 18 | public List Comments { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Models/TagModel.cs: -------------------------------------------------------------------------------- 1 | namespace Blog.Api.Models 2 | { 3 | public class TagModel : BaseModel 4 | { 5 | public string Title { get; set; } 6 | public string Description { get; set; } 7 | public string Slug { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace Blog.Api 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:8915", 8 | "sslPort": 44312 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "Blog.Api": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Blog.Api 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Api/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "ConnectionStrings": { 10 | "BlogConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyBlogDb; Integrated Security=True;" 11 | }, 12 | "AllowedHosts": "*" 13 | } 14 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business.Contracts/Blog.Business.Contracts.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business.Contracts/IBaseBusiness.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using Blog.Data.EF; 8 | 9 | namespace Blog.Business.Contracts 10 | { 11 | public interface IBaseBusiness where TEntity: BaseEntity 12 | { 13 | Task> GetAllAsync(); 14 | 15 | Task GetByIdAsync(int id); 16 | 17 | Task CreateAsync(TEntity entity); 18 | 19 | Task UpdateAsync(TEntity entity); 20 | 21 | Task DeleteAsync(int id); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business.Contracts/ICategoriesBusiness.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.EF.Entities; 3 | 4 | namespace Blog.Business.Contracts 5 | { 6 | public interface ICategoriesBusiness : IBaseBusiness 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business.Contracts/IPostsBusiness.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Blog.Data.EF.Entities; 4 | 5 | namespace Blog.Business.Contracts 6 | { 7 | public interface IPostsBusiness : IBaseBusiness 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business.Contracts/ITagsBusiness.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.EF.Entities; 3 | 4 | namespace Blog.Business.Contracts 5 | { 6 | public interface ITagsBusiness : IBaseBusiness 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business/Blog.Business.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business/CategoriesBusiness.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using Blog.Business.Contracts; 8 | using Blog.Data.Contracts; 9 | using Blog.Data.EF.Entities; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace Blog.Business 13 | { 14 | public class CategoriesBusiness : BaseBusiness, ICategoriesBusiness 15 | { 16 | public CategoriesBusiness(ICategoriesRepository repository, ILogger logger) 17 | : base(repository, logger) 18 | { 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business/PostsBusiness.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | using Blog.Business.Contracts; 5 | using Blog.Data; 6 | using Blog.Data.Contracts; 7 | using Blog.Data.Contracts.Specifications; 8 | using Blog.Data.EF.Entities; 9 | 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace Blog.Business 13 | { 14 | public class PostsBusiness : BaseBusiness, IPostsBusiness 15 | { 16 | public PostsBusiness(IPostsRepository repository, ILogger logger) 17 | : base(repository, logger) 18 | { 19 | 20 | } 21 | 22 | public Task GetById(int id) 23 | { 24 | return Repository.GetByIdAsync(id); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Business/TagsBusiness.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using Blog.Business.Contracts; 8 | using Blog.Data.Contracts; 9 | using Blog.Data.EF.Entities; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace Blog.Business 13 | { 14 | public class TagsBusiness : BaseBusiness, ITagsBusiness 15 | { 16 | public TagsBusiness(ITagsRepository repository, ILogger logger) 17 | : base(repository, logger) 18 | { 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/Blog.Data.Contracts.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/IBaseRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | 4 | using Blog.Data.Contracts.Specifications; 5 | using Blog.Data.EF; 6 | 7 | namespace Blog.Data.Contracts 8 | { 9 | public interface IBaseRepository where TEntity : BaseEntity 10 | { 11 | Task> GetAllAsync(); 12 | 13 | Task GetByIdAsync(int id, IBaseSpecifications baseSpecifications = null); 14 | 15 | Task CreateAsync(TEntity entity); 16 | 17 | Task UpdateAsync(TEntity entity); 18 | 19 | Task DeleteAsync(int id); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/ICategoriesRepository.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.EF.Entities; 3 | 4 | namespace Blog.Data.Contracts 5 | { 6 | public interface ICategoriesRepository : IBaseRepository 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/IPostsRepository.cs: -------------------------------------------------------------------------------- 1 | using Blog.Data.EF.Entities; 2 | 3 | namespace Blog.Data.Contracts 4 | { 5 | public interface IPostsRepository: IBaseRepository 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/ITagsRepository.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.EF.Entities; 3 | 4 | namespace Blog.Data.Contracts 5 | { 6 | public interface ITagsRepository : IBaseRepository 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/Specifications/IBaseSpecifications.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | 5 | namespace Blog.Data.Contracts.Specifications 6 | { 7 | public interface IBaseSpecifications 8 | { 9 | Expression> FilterCondition { get; } 10 | Expression> OrderBy { get; } 11 | Expression> OrderByDescending { get; } 12 | List>> Includes { get; } 13 | Expression> GroupBy { get; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.Contracts/Specifications/PostRelatedDataSpecifications.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Blog.Data.EF.Entities; 4 | 5 | namespace Blog.Data.Contracts.Specifications 6 | { 7 | public class PostRelatedDataSpecifications : BaseSpecifications 8 | { 9 | public PostRelatedDataSpecifications(int id) : base() 10 | { 11 | SetFilterCondition(post => post.Id == id); 12 | AddInclude(post => post.PostTags); 13 | AddInclude(post => post.PostCategories); 14 | AddInclude(post => post.Comments); 15 | } 16 | } 17 | 18 | public class PostsWithoutCommentsSpecification: BaseSpecifications 19 | { 20 | public PostsWithoutCommentsSpecification() : base() 21 | { 22 | SetFilterCondition(post => post.Comments.Count == 0); 23 | } 24 | } 25 | 26 | public class PostsCreatedInLastMonthSpecification : BaseSpecifications 27 | { 28 | public PostsCreatedInLastMonthSpecification() : base() 29 | { 30 | SetFilterCondition(post => post.CreatedOn >= DateTime.Now.AddMonths(-1)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Blog.Data.EF 8 | { 9 | public class BaseEntity 10 | { 11 | public int Id { get; set; } 12 | public bool IsPublished { get; set; } 13 | public DateTime CreatedOn { get; set; } 14 | public DateTime LastModifiedOn { get; set; } 15 | public DateTime PublishedOn { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Blog.Data.EF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/DesignTimeBlogContextFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.EntityFrameworkCore.Design; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | using Microsoft.Extensions.Configuration; 11 | 12 | namespace Blog.Data.EF 13 | { 14 | 15 | public class DesignTimeBlogContextFactory : IDesignTimeDbContextFactory 16 | { 17 | public BlogContext CreateDbContext(string[] args) 18 | { 19 | //var configuration = new ConfigurationBuilder() 20 | // .SetBasePath(Directory.GetCurrentDirectory()) 21 | // .AddJsonFile("appsettings.json") 22 | // .Build(); 23 | 24 | var dbContextBuilder = new DbContextOptionsBuilder(); 25 | 26 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyBlogDb; Integrated Security=True;"; 27 | 28 | dbContextBuilder.UseSqlServer(connectionString); 29 | 30 | return new BlogContext(dbContextBuilder.Options); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/Category.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Blog.Data.EF.Entities 4 | { 5 | public class Category : BaseEntity 6 | { 7 | public string Title { get; set; } 8 | public string Description { get; set; } 9 | public string Slug { get; set; } 10 | public List AssociatedPosts { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/Comment.cs: -------------------------------------------------------------------------------- 1 | namespace Blog.Data.EF.Entities 2 | { 3 | public class Comment : BaseEntity 4 | { 5 | public string CommentContents { get; set; } 6 | 7 | public string PostedBy { get; set; } 8 | 9 | public Comment Parent { get; set; } 10 | 11 | public Post ParentPost { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/Post.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Blog.Data.EF.Entities 4 | { 5 | public class Post : BaseEntity 6 | { 7 | public string Title { get; set; } 8 | public string Slug { get; set; } 9 | public string Summary { get; set; } 10 | public string PostContents { get; set; } 11 | public List PostTags { get; set; } 12 | public List PostCategories { get; set; } 13 | public List Comments { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/PostCategories.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Blog.Data.EF.Entities 8 | { 9 | public class PostCategories 10 | { 11 | public int Id { get; set; } 12 | public int PostId { get; set; } 13 | public Post Post { get; set; } 14 | public int CategoryId { get; set; } 15 | public Category Category { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/PostTags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Blog.Data.EF.Entities 8 | { 9 | public class PostTags 10 | { 11 | public int Id { get; set; } 12 | public int PostId { get; set; } 13 | public Post Post { get; set; } 14 | public int TagId { get; set; } 15 | public Tag Tag { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/Tag.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Blog.Data.EF.Entities 4 | { 5 | public class Tag : BaseEntity 6 | { 7 | public string Title { get; set; } 8 | 9 | public string Description { get; set; } 10 | 11 | public string Slug { get; set; } 12 | 13 | public List PostTags { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Blog.Data.EF.Entities 9 | { 10 | public class User 11 | { 12 | public int Id { get; set; } 13 | 14 | public string FirstName { get; set; } 15 | 16 | public string LastName { get; set; } 17 | 18 | // Data annotation for specifying auto-generated concurrency token 19 | // Uncomment if you want to use data annotation instead of fluent API 20 | // [Timestamp] 21 | public byte[] Version { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data.EF/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context BlogContext 2 | 3 | dotnet ef migrations remove --context BlogContext 4 | 5 | dotnet ef migrations add InitialCreate --context BlogContext 6 | 7 | dotnet ef database update --context BlogContext -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data/Blog.Data.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data/CategoriesRepository.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.Contracts; 3 | using Blog.Data.EF; 4 | using Blog.Data.EF.Entities; 5 | 6 | namespace Blog.Data 7 | { 8 | public class CategoriesRepository : BaseRepository, ICategoriesRepository 9 | { 10 | public CategoriesRepository(BlogContext blogContext) : base(blogContext) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data/PostsRepository.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.Contracts; 3 | using Blog.Data.EF; 4 | using Blog.Data.EF.Entities; 5 | 6 | namespace Blog.Data 7 | { 8 | public class PostsRepository : BaseRepository, IPostsRepository 9 | { 10 | public PostsRepository(BlogContext blogContext) : base(blogContext) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EFCoreBlogDemo/Blog.Data/TagsRepository.cs: -------------------------------------------------------------------------------- 1 |  2 | using Blog.Data.Contracts; 3 | using Blog.Data.EF; 4 | using Blog.Data.EF.Entities; 5 | 6 | namespace Blog.Data 7 | { 8 | public class TagsRepository: BaseRepository, ITagsRepository 9 | { 10 | public TagsRepository(BlogContext blogContext) : base(blogContext) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EFCoreConcepts/EFCoreConcepts.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "University.Data.EF.Models", "University.Data.EF.Models\University.Data.EF.Models.csproj", "{294ED933-FB91-4946-8A29-2A788D4F9A84}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1549156C-A197-4BDD-B771-D465CE4105EB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /EFCoreConcepts/University.Data.EF.Models/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.EntityFrameworkCore.Design; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | using Microsoft.Extensions.Configuration; 11 | 12 | namespace University.Data.EF.Models 13 | { 14 | 15 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 16 | { 17 | public UniversityContext CreateDbContext(string[] args) 18 | { 19 | //var configuration = new ConfigurationBuilder() 20 | // .SetBasePath(Directory.GetCurrentDirectory()) 21 | // .AddJsonFile("appsettings.json") 22 | // .Build(); 23 | 24 | var dbContextBuilder = new DbContextOptionsBuilder(); 25 | 26 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 27 | 28 | dbContextBuilder.UseSqlServer(connectionString); 29 | 30 | return new UniversityContext(dbContextBuilder.Options); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /EFCoreConcepts/University.Data.EF.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | using Microsoft.EntityFrameworkCore.Metadata.Internal; 6 | 7 | namespace University.Data.EF.Models 8 | { 9 | public class Student 10 | { 11 | public int Id { get; set; } 12 | 13 | public string FirstName { get; set; } 14 | 15 | public string LastName { get; set; } 16 | 17 | public string Address { get; set; } 18 | 19 | public DateTime? CreatedOn { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /EFCoreConcepts/University.Data.EF.Models/University.Data.EF.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /EFCoreConcepts/University.Data.EF.Models/UniversityContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using Microsoft.EntityFrameworkCore; 8 | 9 | namespace University.Data.EF.Models 10 | { 11 | public class UniversityContext : DbContext 12 | { 13 | public UniversityContext(DbContextOptions options) 14 | : base(options) 15 | { 16 | } 17 | 18 | protected override void OnModelCreating(ModelBuilder modelBuilder) 19 | { 20 | // Method 1 - Call configure method 21 | // var studentConfigurations = new StudentEntityTypeConfiguration(); 22 | // studentConfigurations.Configure(modelBuilder.Entity()); 23 | 24 | //// Method 2 - ApplyConfiguration method 25 | // modelBuilder.ApplyConfiguration(studentConfigurations); 26 | 27 | // Method 3 - Apply all from an assembly 28 | modelBuilder.ApplyConfigurationsFromAssembly(typeof(UniversityContext).Assembly); 29 | } 30 | 31 | public DbSet Students { get; set; } 32 | } 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/DeleteExamples.Data.EF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Design; 3 | 4 | namespace DeleteExamples.Data.EF 5 | { 6 | 7 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 8 | { 9 | public UniversityContext CreateDbContext(string[] args) 10 | { 11 | var dbContextBuilder = new DbContextOptionsBuilder(); 12 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 13 | dbContextBuilder.UseSqlServer(connectionString); 14 | return new UniversityContext(dbContextBuilder.Options); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/Author.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace DeleteExamples.Data.EF.Entities 9 | { 10 | public class Author 11 | { 12 | public int Id { get; set; } 13 | public string Name { get; set; } 14 | public Book Book { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/Book.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace DeleteExamples.Data.EF.Entities 9 | { 10 | public class Book 11 | { 12 | public int Id { get; set; } 13 | public string Name { get; set; } 14 | 15 | [ForeignKey(nameof(Author))] 16 | public int AuthorId { get; set; } 17 | public Author Author { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace DeleteExamples.Data.EF.Entities 5 | { 6 | public class Country 7 | { 8 | public int Id { get; set; } 9 | public string Name { get; set; } 10 | public List CountryLanguages { get; set; } 11 | 12 | public override string ToString() 13 | { 14 | return $"{{ Id: {Id}, Name: {Name} }}"; 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/CountryLanguage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DeleteExamples.Data.EF.Entities 8 | { 9 | public class CountryLanguage 10 | { 11 | public int Id { get; set; } 12 | public int CountryId { get; set; } 13 | public Country AssociatedCountry { get; set; } 14 | public int LanguageId { get; set; } 15 | public Language AssociatedLanguage { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/Language.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace DeleteExamples.Data.EF.Entities 5 | { 6 | 7 | public class Language 8 | { 9 | public int Id { get; set; } 10 | public string Name { get; set; } 11 | public List CountryLanguages { get; set; } 12 | 13 | public override string ToString() 14 | { 15 | return $"{{ Id: {Id}, Name: {Name} }}"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace DeleteExamples.Data.EF.Entities 9 | { 10 | public class Student 11 | { 12 | public int Id { get; set; } 13 | 14 | public string Name { get; set; } 15 | 16 | [ForeignKey(nameof(Teacher))] 17 | public int TeacherId { get; set; } 18 | 19 | public Teacher Teacher { get; set; } 20 | 21 | public override string ToString() 22 | { 23 | return $"{{ Id: {Id}, Name: {Name} }}"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/Entities/Teacher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace DeleteExamples.Data.EF.Entities 5 | { 6 | public class Teacher 7 | { 8 | public int Id { get; set; } 9 | public string Name { get; set; } 10 | public List Students { get; set; } 11 | public override string ToString() 12 | { 13 | return $"{{ Id: {Id}, Name: {Name} }}"; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples.Data.EF/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context UniversityContext 2 | 3 | dotnet ef migrations remove --context UniversityContext 4 | 5 | dotnet ef migrations add InitialCreate --context UniversityContext 6 | 7 | dotnet ef database update --context UniversityContext -------------------------------------------------------------------------------- /EFCoreDeleteExamples/DeleteExamples/DeleteExamples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /EFCoreFunctionsDemo/EFCoreFunctionsDemo.Data.EF/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Design; 3 | 4 | namespace EFCoreFunctionsDemo.Data.EF 5 | { 6 | 7 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 8 | { 9 | public UniversityContext CreateDbContext(string[] args) 10 | { 11 | var dbContextBuilder = new DbContextOptionsBuilder(); 12 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 13 | dbContextBuilder.UseSqlServer(connectionString); 14 | return new UniversityContext(dbContextBuilder.Options); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreFunctionsDemo/EFCoreFunctionsDemo.Data.EF/EFCoreFunctionsDemo.Data.EF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EFCoreFunctionsDemo/EFCoreFunctionsDemo.Data.EF/FunctionMappingUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EFCoreFunctionsDemo.Data.EF 8 | { 9 | public class FunctionMappingUtil 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /EFCoreFunctionsDemo/EFCoreFunctionsDemo.Data.EF/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EFCoreFunctionsDemo.Data.EF 4 | { 5 | public class Student 6 | { 7 | public int Id { get; set; } 8 | 9 | public string FirstName { get; set; } 10 | 11 | public string LastName { get; set; } 12 | 13 | public string Address { get; set; } 14 | 15 | public DateTime CreatedOn { get; set; } 16 | public DateTime ModifiedOn { get; set; } 17 | public DateTime DeletedOn { get; set; } 18 | 19 | public override string ToString() 20 | => $"{{ Id: {Id}, FirstName={FirstName}, LastName:{LastName} }}"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EFCoreFunctionsDemo/EFCoreFunctionsDemo.Data.EF/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context UniversityContext 2 | 3 | dotnet ef migrations remove --context UniversityContext 4 | 5 | dotnet ef migrations add InitialCreate --context UniversityContext 6 | 7 | dotnet ef database update --context UniversityContext -------------------------------------------------------------------------------- /EFCoreFunctionsDemo/EFCoreFunctionsDemo/EFCoreFunctionsDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.Data.EF/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Design; 3 | 4 | namespace EFCoreGlobalFiltersDemo.Data.EF 5 | { 6 | 7 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 8 | { 9 | public UniversityContext CreateDbContext(string[] args) 10 | { 11 | var dbContextBuilder = new DbContextOptionsBuilder(); 12 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 13 | dbContextBuilder.UseSqlServer(connectionString); 14 | return new UniversityContext(dbContextBuilder.Options); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.Data.EF/EFCoreGlobalFiltersDemo.Data.EF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.Data.EF/FunctionMappingUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EFCoreGlobalFiltersDemo.Data.EF 8 | { 9 | public class FunctionMappingUtil 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.Data.EF/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EFCoreGlobalFiltersDemo.Data.EF 4 | { 5 | public class Student 6 | { 7 | public int Id { get; set; } 8 | 9 | public string FirstName { get; set; } 10 | 11 | public string LastName { get; set; } 12 | 13 | public string Address { get; set; } 14 | 15 | public string Nationality { get; set; } 16 | 17 | public DateTime CreatedOn { get; set; } 18 | 19 | public DateTime ModifiedOn { get; set; } 20 | 21 | public bool IsDeleted { get; set; } 22 | 23 | public DateTime DeletedOn { get; set; } 24 | 25 | public override string ToString() 26 | => $"{{ Id: {Id}, FirstName={FirstName}, LastName:{LastName}, IsDeleted={IsDeleted} }}"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.Data.EF/UniversityContext.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Reflection.Metadata; 4 | 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace EFCoreGlobalFiltersDemo.Data.EF 8 | { 9 | public class UniversityContext : DbContext 10 | { 11 | public UniversityContext(DbContextOptions options) 12 | : base(options) 13 | { 14 | } 15 | 16 | protected override void OnModelCreating(ModelBuilder modelBuilder) 17 | { 18 | modelBuilder.Entity().HasQueryFilter(s => !s.IsDeleted); 19 | } 20 | 21 | public DbSet Students { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.Data.EF/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context UniversityContext 2 | 3 | dotnet ef migrations remove --context UniversityContext 4 | 5 | dotnet ef migrations add InitialCreate --context UniversityContext 6 | 7 | dotnet ef database update --context UniversityContext -------------------------------------------------------------------------------- /EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo/EFCoreGlobalFiltersDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /EFCoreInterceptorsDemo/EFCoreInterceptorsDemo.Data.EF/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Design; 3 | 4 | namespace EFCoreInterceptorsDemo.Data.EF 5 | { 6 | 7 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 8 | { 9 | public UniversityContext CreateDbContext(string[] args) 10 | { 11 | //var configuration = new ConfigurationBuilder() 12 | // .SetBasePath(Directory.GetCurrentDirectory()) 13 | // .AddJsonFile("appsettings.json") 14 | // .Build(); 15 | 16 | var dbContextBuilder = new DbContextOptionsBuilder(); 17 | 18 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 19 | 20 | dbContextBuilder.UseSqlServer(connectionString); 21 | 22 | return new UniversityContext(dbContextBuilder.Options); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /EFCoreInterceptorsDemo/EFCoreInterceptorsDemo.Data.EF/EFCoreInterceptorsDemo.Data.EF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EFCoreInterceptorsDemo/EFCoreInterceptorsDemo.Data.EF/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EFCoreInterceptorsDemo.Data.EF 4 | { 5 | public class Student 6 | { 7 | public int Id { get; set; } 8 | 9 | public string FirstName { get; set; } 10 | 11 | public string LastName { get; set; } 12 | 13 | public string Address { get; set; } 14 | 15 | public DateTime CreatedOn { get; set; } 16 | public DateTime ModifiedOn { get; set; } 17 | public DateTime DeletedOn { get; set; } 18 | 19 | public override string ToString() 20 | => $"{{ Id: {Id}, FirstName={FirstName}, LastName:{LastName} }}"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EFCoreInterceptorsDemo/EFCoreInterceptorsDemo.Data.EF/UniversityContext.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace EFCoreInterceptorsDemo.Data.EF 5 | { 6 | public class UniversityContext : DbContext 7 | { 8 | public UniversityContext(DbContextOptions options) 9 | : base(options) 10 | { 11 | 12 | } 13 | 14 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 15 | { 16 | // ALERT - DEMO CODE 17 | // You may want to inject the interceptors into the context 18 | optionsBuilder.AddInterceptors(new DemoDbCommandInterceptor()); 19 | } 20 | 21 | public DbSet Students { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EFCoreInterceptorsDemo/EFCoreInterceptorsDemo.Data.EF/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context UniversityContext 2 | 3 | dotnet ef migrations remove --context UniversityContext 4 | 5 | dotnet ef migrations add InitialCreate --context UniversityContext 6 | 7 | dotnet ef database update --context UniversityContext -------------------------------------------------------------------------------- /EFCoreInterceptorsDemo/EFCoreInterceptorsDemo/EFCoreInterceptorsDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /EFCoreRelationships/EFCoreRelationships.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "University.Data.EF.Models", "University.Data.EF.Models\University.Data.EF.Models.csproj", "{294ED933-FB91-4946-8A29-2A788D4F9A84}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {294ED933-FB91-4946-8A29-2A788D4F9A84}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1549156C-A197-4BDD-B771-D465CE4105EB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /EFCoreRelationships/University.Data.EF.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace University.Data.EF.Models 8 | { 9 | public class Course 10 | { 11 | public int Id { get; set; } 12 | public string Name { get; set; } 13 | public string Description { get; set; } 14 | public List ModuleCollection { get; set; } 15 | } 16 | 17 | public class Module 18 | { 19 | public int Id { get; set; } 20 | public string Name { get; set; } 21 | public string Description { get; set; } 22 | // public int CourseId { get; set; } 23 | // public Course Course { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /EFCoreRelationships/University.Data.EF.Models/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.EntityFrameworkCore.Design; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | using Microsoft.Extensions.Configuration; 11 | 12 | namespace University.Data.EF.Models 13 | { 14 | 15 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 16 | { 17 | public UniversityContext CreateDbContext(string[] args) 18 | { 19 | //var configuration = new ConfigurationBuilder() 20 | // .SetBasePath(Directory.GetCurrentDirectory()) 21 | // .AddJsonFile("appsettings.json") 22 | // .Build(); 23 | 24 | var dbContextBuilder = new DbContextOptionsBuilder(); 25 | 26 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 27 | 28 | dbContextBuilder.UseSqlServer(connectionString); 29 | 30 | return new UniversityContext(dbContextBuilder.Options); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /EFCoreRelationships/University.Data.EF.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | using Microsoft.EntityFrameworkCore.Metadata.Internal; 6 | 7 | namespace University.Data.EF.Models 8 | { 9 | public class Student 10 | { 11 | public int Id { get; set; } 12 | 13 | public string FirstName { get; set; } 14 | 15 | public string LastName { get; set; } 16 | 17 | public string Address { get; set; } 18 | 19 | public DateTime? CreatedOn { get; set; } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /EFCoreRelationships/University.Data.EF.Models/University.Data.EF.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /EFCoreRelationships/University.Data.EF.Models/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context UniversityContext 2 | 3 | dotnet ef migrations remove --context UniversityContext 4 | 5 | dotnet ef migrations add InitialCreate --context UniversityContext 6 | 7 | dotnet ef database update --context UniversityContext -------------------------------------------------------------------------------- /EventsDemo/EventsDemo.Data.EF/DesignTimeUniversityContextFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Design; 3 | 4 | namespace EventsDemo.Data.EF 5 | { 6 | 7 | public class DesignTimeUniversityContextFactory : IDesignTimeDbContextFactory 8 | { 9 | public UniversityContext CreateDbContext(string[] args) 10 | { 11 | //var configuration = new ConfigurationBuilder() 12 | // .SetBasePath(Directory.GetCurrentDirectory()) 13 | // .AddJsonFile("appsettings.json") 14 | // .Build(); 15 | 16 | var dbContextBuilder = new DbContextOptionsBuilder(); 17 | 18 | var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=University; Integrated Security=True;"; 19 | 20 | dbContextBuilder.UseSqlServer(connectionString); 21 | 22 | return new UniversityContext(dbContextBuilder.Options); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /EventsDemo/EventsDemo.Data.EF/EventsDemo.Data.EF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EventsDemo/EventsDemo.Data.EF/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EventsDemo.Data.EF 4 | { 5 | public class Student 6 | { 7 | public int Id { get; set; } 8 | 9 | public string FirstName { get; set; } 10 | 11 | public string LastName { get; set; } 12 | 13 | public string Address { get; set; } 14 | 15 | public DateTime CreatedOn { get; set; } 16 | public DateTime ModifiedOn { get; set; } 17 | public DateTime DeletedOn { get; set; } 18 | 19 | public override string ToString() 20 | => $"Student Id ={Id}, FirstName={FirstName}"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EventsDemo/EventsDemo.Data.EF/ef-core-commands.bat: -------------------------------------------------------------------------------- 1 | dotnet ef database update 0 --context UniversityContext 2 | 3 | dotnet ef migrations remove --context UniversityContext 4 | 5 | dotnet ef migrations add InitialCreate --context UniversityContext 6 | 7 | dotnet ef database update --context UniversityContext -------------------------------------------------------------------------------- /EventsDemo/EventsDemoConsole/EventsDemoConsole.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/ExceptionHandlingDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiDemo", "WebApiDemo\WebApiDemo.csproj", "{4ABA60F4-38DB-4415-83FE-0AC0D4BE83A3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4ABA60F4-38DB-4415-83FE-0AC0D4BE83A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4ABA60F4-38DB-4415-83FE-0AC0D4BE83A3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4ABA60F4-38DB-4415-83FE-0AC0D4BE83A3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4ABA60F4-38DB-4415-83FE-0AC0D4BE83A3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {31E6093E-16B3-4ADD-9DE9-F83711CAED53} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/Controllers/ErrorController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace WebApiDemo.Controllers 4 | { 5 | [ApiController] 6 | public class ErrorController : ControllerBase 7 | { 8 | [Route("/error")] 9 | public IActionResult Error() => Problem(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/Controllers/GetValueController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace WebApiDemo.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class GetValueController : ControllerBase 14 | { 15 | private readonly ILogger _logger; 16 | 17 | public GetValueController(ILogger logger) 18 | { 19 | _logger = logger; 20 | } 21 | 22 | [HttpGet] 23 | [CustomExceptionFilter] 24 | public IActionResult Get(string key) 25 | { 26 | if (string.IsNullOrEmpty(key)) 27 | { 28 | throw new ArgumentException(); 29 | } 30 | 31 | return Ok("Value"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/CustomExceptionFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.AspNetCore.Mvc.Filters; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace WebApiDemo 11 | { 12 | public class CustomExceptionFilterAttribute : ExceptionFilterAttribute 13 | { 14 | private readonly ILogger _logger; 15 | 16 | public CustomExceptionFilterAttribute(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | public override void OnException(ExceptionContext context) 22 | { 23 | base.OnException(context); 24 | 25 | // Some logic to handle specific exceptions 26 | var errorMessage = context.Exception is ArgumentException 27 | ? "ArgumentException occurred" 28 | : "Some unknown error occurred"; 29 | 30 | // Maybe, logging the exception 31 | _logger.LogError(context.Exception, errorMessage); 32 | 33 | // Returning response 34 | context.Result = new BadRequestResult(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:15644", 8 | "sslPort": 44322 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiDemo": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiDemo 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/WebApiDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ExceptionHandlingDemo/WebApiDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClientDemo", "HttpClientDemo\HttpClientDemo.csproj", "{C1C652D3-2EB1-4EAE-A1F2-F8430D99A2CA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C1C652D3-2EB1-4EAE-A1F2-F8430D99A2CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C1C652D3-2EB1-4EAE-A1F2-F8430D99A2CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C1C652D3-2EB1-4EAE-A1F2-F8430D99A2CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C1C652D3-2EB1-4EAE-A1F2-F8430D99A2CA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {42751C4D-CEC1-429D-8D94-8155EA2BA71D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/GitHubApionsumer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Text.Json; 6 | using System.Threading.Tasks; 7 | 8 | namespace HttpClientDemo 9 | { 10 | public class GitHubApionsumer 11 | { 12 | private readonly HttpClient _httpClient; 13 | 14 | public GitHubApionsumer(HttpClient httpClient) 15 | { 16 | _httpClient = httpClient; 17 | } 18 | 19 | public async Task> GetRepos() 20 | { 21 | var response = await _httpClient.GetAsync("users/aspnet/repos"); 22 | 23 | response.EnsureSuccessStatusCode(); 24 | 25 | using var responseStream = await response.Content.ReadAsStreamAsync(); 26 | return await JsonSerializer.DeserializeAsync 27 | >(responseStream); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/HttpClientDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HttpClientDemo.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace HttpClientDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37992", 7 | "sslPort": 44356 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "HttpClientDemo": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome

7 |

Learn about building Web apps with ASP.NET Core.

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | @foreach (var repo in ViewBag.repoCollection) 21 | { 22 | 23 | 24 | 25 | 26 | 27 | 28 | } 29 | 30 |
#NameFull NameUrl
#@repo.Name@repo.FullName@repo.Url
31 |
32 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using HttpClientDemo 2 | @using HttpClientDemo.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manoj-choudhari-git/dotnet-on-thecodeblogger/12eb7fcbad283d54c391edc440cc99c4ef549921/HttpClientDemo-Typed/HttpClientDemo/wwwroot/favicon.ico -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /HttpClientDemo-Typed/HttpClientDemo/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Manoj Choudhari 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LoggingExamples/HostBasedConsoleApp/HostBasedConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /LoggingExamples/HostBasedConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.Hosting; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace HostBasedConsoleApp 9 | { 10 | class Program 11 | { 12 | static Task Main(string[] args) 13 | { 14 | var host = CreateHostBuilder(args).Build(); 15 | var workerInstance = host.Services.GetRequiredService(); 16 | workerInstance.Execute(); 17 | return host.RunAsync(); 18 | } 19 | 20 | static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureServices((_, services) => 23 | { 24 | services.AddTransient(); 25 | }) 26 | .ConfigureLogging((_, logging) => 27 | { 28 | logging.ClearProviders(); 29 | logging.AddSimpleConsole(options => options.IncludeScopes = true); 30 | logging.AddEventLog(); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LoggingExamples/HostBasedConsoleApp/Worker.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | 3 | namespace HostBasedConsoleApp 4 | { 5 | internal class Worker 6 | { 7 | private readonly ILogger logger; 8 | 9 | public Worker(ILogger logger) 10 | { 11 | this.logger = logger; 12 | } 13 | public void Execute() 14 | { 15 | logger.LogInformation("This is Info log"); 16 | logger.LogWarning("This is Warning log"); 17 | logger.LogError("This is Error log"); 18 | logger.LogCritical("This is Critical log"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /LoggingExamples/NonHostConsole/NonHostConsole.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LoggingExamples/NonHostConsole/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace NonHostConsole 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | using var loggerFactory = LoggerFactory.Create(builder => 12 | { 13 | builder 14 | .AddFilter("Microsoft", LogLevel.Warning) 15 | .AddFilter("System", LogLevel.Warning) 16 | .AddFilter("NonHostConsoleApp.Program", LogLevel.Debug) 17 | .AddConsole(); 18 | }); 19 | ILogger logger = loggerFactory.CreateLogger(); 20 | logger.LogInformation("Info Log"); 21 | logger.LogWarning("Warning Log"); 22 | logger.LogError("Error Log"); 23 | logger.LogCritical("Critical Log"); 24 | Console.ReadLine(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAppLoggingExample.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:51665", 7 | "sslPort": 44377 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "WebAppLoggingExample": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome

7 |

Learn about building Web apps with ASP.NET Core.

8 |
9 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using WebAppLoggingExample 2 | @using WebAppLoggingExample.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/WebAppLoggingExample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manoj-choudhari-git/dotnet-on-thecodeblogger/12eb7fcbad283d54c391edc440cc99c4ef549921/LoggingExamples/WebAppLoggingExample/wwwroot/favicon.ico -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /LoggingExamples/WebAppLoggingExample/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31112.23 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OptionsExample", "OptionsExample\OptionsExample.csproj", "{C37E40D6-1B07-427A-8172-01DF169AF7AE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C37E40D6-1B07-427A-8172-01DF169AF7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C37E40D6-1B07-427A-8172-01DF169AF7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C37E40D6-1B07-427A-8172-01DF169AF7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C37E40D6-1B07-427A-8172-01DF169AF7AE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1D409CB6-EFD6-4227-8D68-96F7A40BE97D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Configurations/MailFeature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace OptionsExample.Configurations 7 | { 8 | public class MailFeature 9 | { 10 | public bool IsEnabled { get; set; } 11 | public string SmtpServer{ get; set; } 12 | public string Subject { get; set; } 13 | public string FromEmailAddress { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace OptionsExample.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/OptionsExample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace OptionsExample 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5882", 7 | "sslPort": 44307 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "OptionsExample": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome

7 |

Learn about building Web apps with ASP.NET Core.

8 |
9 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using OptionsExample 2 | @using OptionsExample.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MailFeature": { 3 | "IsEnabled": true, 4 | "SmtpServer": "some-dns.smtp.local", 5 | "Subject": "Very important email", 6 | "FromEmailAddress": "no-reply@mysite.com" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manoj-choudhari-git/dotnet-on-thecodeblogger/12eb7fcbad283d54c391edc440cc99c4ef549921/OptionsExample/OptionsExample/wwwroot/favicon.ico -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2018 Twitter, Inc. 4 | Copyright (c) 2011-2018 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /OptionsExample/OptionsExample/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /PassByReferenceDemo/ParametersDemo/ParametersDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PassByReferenceDemo/ParametersDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ParametersDemo 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | ValueTypeDemo valueTypeDemo = new ValueTypeDemo(); 10 | valueTypeDemo.Execute(); 11 | 12 | ReferenceTypeDemo referenceTypeDemo = new ReferenceTypeDemo(); 13 | referenceTypeDemo.Execute(); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PassByReferenceDemo/PassByReferenceDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParametersDemo", "ParametersDemo\ParametersDemo.csproj", "{378709ED-01C1-4D58-805C-852271AF1245}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {378709ED-01C1-4D58-805C-852271AF1245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {378709ED-01C1-4D58-805C-852271AF1245}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {378709ED-01C1-4D58-805C-852271AF1245}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {378709ED-01C1-4D58-805C-852271AF1245}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7ED39DDD-B8B6-4B1E-9A86-856B0A279329} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /RecordExample/RecordExample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31911.196 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecordExample", "RecordExample\RecordExample.csproj", "{F5F76538-5347-4977-94FB-1B001429E36B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F5F76538-5347-4977-94FB-1B001429E36B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F5F76538-5347-4977-94FB-1B001429E36B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F5F76538-5347-4977-94FB-1B001429E36B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F5F76538-5347-4977-94FB-1B001429E36B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {CBE70AB7-6180-4846-9252-148C610DE387} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /RecordExample/RecordExample/RecordExample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiAutoMapperDemo", "WebApiAutoMapperDemo\WebApiAutoMapperDemo.csproj", "{C67D584F-1566-4557-81E0-4624D9BFC41C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C67D584F-1566-4557-81E0-4624D9BFC41C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C67D584F-1566-4557-81E0-4624D9BFC41C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C67D584F-1566-4557-81E0-4624D9BFC41C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C67D584F-1566-4557-81E0-4624D9BFC41C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {BA199B7B-AC05-4AEC-8C4A-8F3995745CF0} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/ApiMappingProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Threading.Tasks; 6 | 7 | using AutoMapper; 8 | 9 | namespace WebApiAutoMapperDemo 10 | { 11 | public class ApiMappingProfile : Profile 12 | { 13 | public ApiMappingProfile() 14 | { 15 | CreateMap().ReverseMap(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiAutoMapperDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:38686", 8 | "sslPort": 44357 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiAutoMapperDemo": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/Source.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace WebApiAutoMapperDemo 7 | { 8 | public class Source 9 | { 10 | public int Id { get; set; } 11 | public string Name { get; set; } 12 | public string Description { get; set; } 13 | 14 | public DateTime CreatedOn { get; set; } 15 | } 16 | 17 | public class Destination 18 | { 19 | public int Id { get; set; } 20 | public string Name { get; set; } 21 | public string Description { get; set; } 22 | 23 | public DateTime CreatedOn { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiAutoMapperDemo 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/WebApiAutoMapperDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiAutoMapperDemo/WebApiAutoMapperDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiDistributedMemoryCache/WebApiDistributedMemoryCache/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiDistributedMemoryCache 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiDistributedMemoryCache/WebApiDistributedMemoryCache/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:9112", 8 | "sslPort": 44312 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiDistributedMemoryCache": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiDistributedMemoryCache/WebApiDistributedMemoryCache/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiDistributedMemoryCache 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiDistributedMemoryCache/WebApiDistributedMemoryCache/WebApiDistributedMemoryCache.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebApiDistributedMemoryCache/WebApiDistributedMemoryCache/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiDistributedMemoryCache/WebApiDistributedMemoryCache/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiDistributedSqlCache", "WebApiDistributedSqlCache\WebApiDistributedSqlCache.csproj", "{82E8A848-1F55-49AE-97E2-B8B89168CAA7}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {82E8A848-1F55-49AE-97E2-B8B89168CAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {82E8A848-1F55-49AE-97E2-B8B89168CAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {82E8A848-1F55-49AE-97E2-B8B89168CAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {82E8A848-1F55-49AE-97E2-B8B89168CAA7}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A07716F3-78E8-4DC7-91FA-AE1C870324AC} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiDistributedSqlCache 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:58092", 8 | "sslPort": 44387 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiDistributedSqlCache": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiDistributedSqlCache 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache/WebApiDistributedSqlCache.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiDistributedSqlCache/WebApiDistributedSqlCache/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "CacheDbConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyCacheDb;Integrated Security=True;" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft": "Warning", 9 | "Microsoft.Hosting.Lifetime": "Information" 10 | } 11 | }, 12 | "AllowedHosts": "*" 13 | } 14 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiInMemoryCaching", "WebApiInMemoryCaching\WebApiInMemoryCaching.csproj", "{BFC1FE7A-ED35-41E6-B56B-F46375A17C1B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BFC1FE7A-ED35-41E6-B56B-F46375A17C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {BFC1FE7A-ED35-41E6-B56B-F46375A17C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {BFC1FE7A-ED35-41E6-B56B-F46375A17C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {BFC1FE7A-ED35-41E6-B56B-F46375A17C1B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {11330285-2B49-471C-951D-815D1FEAEBAA} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiInMemoryCaching 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40439", 8 | "sslPort": 44360 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiInMemoryCaching": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiInMemoryCaching 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching/WebApiInMemoryCaching.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiInMemoryCaching/WebApiInMemoryCaching/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiModelValidationDemo", "WebApiModelValidationDemo\WebApiModelValidationDemo.csproj", "{232DAE36-3A0F-41AB-B032-85DC442D9D92}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {232DAE36-3A0F-41AB-B032-85DC442D9D92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {232DAE36-3A0F-41AB-B032-85DC442D9D92}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {232DAE36-3A0F-41AB-B032-85DC442D9D92}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {232DAE36-3A0F-41AB-B032-85DC442D9D92}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {DF4910F8-451D-4102-BEA7-81A8B04F9A1B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.Mvc; 9 | 10 | using WebApiModelValidationDemo.Models; 11 | 12 | namespace WebApiModelValidationDemo 13 | { 14 | 15 | 16 | [Route("api/[controller]")] 17 | [ApiController] 18 | public class EmployeeController : ControllerBase 19 | { 20 | [HttpPost] 21 | public Employee Post([FromBody] Employee employee) 22 | { 23 | return employee; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiModelValidationDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:50865", 8 | "sslPort": 44376 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiModelValidationDemo": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiModelValidationDemo 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/WebApiModelValidationDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiModelValidationDemo/WebApiModelValidationDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiOrderedFilterDemo", "WebApiOrderedFilterDemo\WebApiOrderedFilterDemo.csproj", "{7052E2D8-BF8A-445E-A71F-54B0F78FFF6F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7052E2D8-BF8A-445E-A71F-54B0F78FFF6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {7052E2D8-BF8A-445E-A71F-54B0F78FFF6F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {7052E2D8-BF8A-445E-A71F-54B0F78FFF6F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {7052E2D8-BF8A-445E-A71F-54B0F78FFF6F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {4C32D97E-2BC2-438A-9D5B-A6FF9416B1DC} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/CustomActionFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using Microsoft.AspNetCore.Mvc.Filters; 8 | using Microsoft.Extensions.Options; 9 | 10 | namespace WebApiOrderedFilterDemo 11 | { 12 | public class CustomActionFilterAttribute : ActionFilterAttribute 13 | { 14 | 15 | public CustomActionFilterAttribute() 16 | { 17 | } 18 | 19 | public string Scope { get; set; } = "Global"; 20 | 21 | public override void OnActionExecuting(ActionExecutingContext context) 22 | { 23 | Debug.WriteLine("OnActionExecuting: " + Name); 24 | base.OnActionExecuting(context); 25 | } 26 | 27 | public override void OnActionExecuted(ActionExecutedContext context) 28 | { 29 | Debug.WriteLine("OnActionExecuted: " + Name); 30 | base.OnActionExecuted(context); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiOrderedFilterDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:59518", 8 | "sslPort": 44389 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiOrderedFilterDemo": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiOrderedFilterDemo 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/WebApiOrderedFilterDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiOrderedFilterDemo/WebApiOrderedFilterDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiResponseCachingDemo", "WebApiResponseCachingDemo\WebApiResponseCachingDemo.csproj", "{79D8990A-BC96-4C09-8E35-3A0648B21401}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {79D8990A-BC96-4C09-8E35-3A0648B21401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {79D8990A-BC96-4C09-8E35-3A0648B21401}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {79D8990A-BC96-4C09-8E35-3A0648B21401}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {79D8990A-BC96-4C09-8E35-3A0648B21401}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {3069DF73-97EE-4263-8BD6-FBEC5BD14D9C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiResponseCachingDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:44666", 8 | "sslPort": 44366 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiResponseCachingDemo": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiResponseCachingDemo 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo/WebApiResponseCachingDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiResponseCachingDemo/WebApiResponseCachingDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiFormatters/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiFormatters 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IHostBuilder CreateHostBuilder(string[] args) => 21 | Host.CreateDefaultBuilder(args) 22 | .ConfigureWebHostDefaults(webBuilder => 23 | { 24 | webBuilder.UseStartup(); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiFormatters/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:59748", 8 | "sslPort": 44390 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebApiFormatters": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiFormatters/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Newtonsoft.Json; 4 | 5 | namespace WebApiFormatters 6 | { 7 | public class WeatherForecast 8 | { 9 | [JsonProperty("d")] 10 | public DateTime Date { get; set; } 11 | 12 | [JsonProperty("tempC")] 13 | public int TemperatureC { get; set; } 14 | 15 | [JsonProperty("tempF")] 16 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 17 | 18 | [JsonProperty("summary")] 19 | public string Summary { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiFormatters/WebApiFormatters.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiFormatters/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiFormatters/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /WebApiResponseFormatters/WebApiResponseFormatters.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiFormatters", "WebApiFormatters\WebApiFormatters.csproj", "{1C82361B-136D-457D-BE25-EEEA981B06CA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1C82361B-136D-457D-BE25-EEEA981B06CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1C82361B-136D-457D-BE25-EEEA981B06CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1C82361B-136D-457D-BE25-EEEA981B06CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1C82361B-136D-457D-BE25-EEEA981B06CA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7BC120DD-EA11-4E63-BAAD-AF1DE630D0B0} 24 | EndGlobalSection 25 | EndGlobal 26 | --------------------------------------------------------------------------------