Questions tagged [microsoft.extensions.hosting]

16 questions
5
votes
1 answer

Use HostBuilder.ConfigureServices with DryIoc container?

I have some class libraries that provide services to the applications I create and for legacy reasons they are tightly bound to DryIoc. That is, the service registrations are tightly bound, not the actual services. If I can I would rather not just…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
3
votes
1 answer

System.Exception: Method not found: 'ILoggerFactory.AddConsole(Microsoft.Extensions.Logging.ILoggerFactory, Microsoft.Extensions.Logging.LogLevel)'

I am trying to upgrade the .netcore framework from 2.2 to 3.1 . But I want to use IHostingEnvironment, IWebHostBuilder and AddNewtonsoftJson in 3.1 also. (I know they should be replaced but if I will do so, code refactoring will be required, which i…
3
votes
2 answers

.NET Generic Host - Is it possible to stop and restart a host?

Consider this extremely simple .NET Core 3.1 (and .NET 5) application with no special config or hosted services: using System.Threading.Tasks; using Microsoft.Extensions.Hosting; internal class Program { public static async Task Main(string[]…
Dunge
  • 532
  • 3
  • 19
3
votes
2 answers

Can not inject IOptions in service

I am trying to inject a IOptions inside a service that I created and it is always null: public class Startup { private IConfiguration configuration; public Startup(IConfiguration config) { this.configuration = config; //gets…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
2
votes
1 answer

What class does an instance of IHost returned by HostBuilder.Build() belong to?

I'm learning about Microsoft.Extensions.Hosting, and I've come across the HostBuilder.Build() method. I can see that it returns an instance of IHost interface ('an initialise IHost', according to learn.microsoft.com), but I don't know what class…
Elon Obama
  • 29
  • 6
2
votes
2 answers

Change service implementation later in execution (in Microsoft.Extensions.DependencyInjection)

I have a use-case (application with login and after that various pages with different functionalities to navigate through) where I register most of my services in the ConfigureServices method (like one would normally do) and hence before the actual…
2
votes
1 answer

Why is an object created by GetService not being destructed?

I am writing an application targeting the dotnet core framework 3.1. I use dependency injection to configure, among others, the database context. In my Program.cs I have the following code: var host = new HostBuilder() …
2
votes
3 answers

Simple Injector integration with HostBuilder in .NET Core 2.x

We are developing a windows service that runs .net core 2.x. Following this blog post by Steve Gordon running .netcore generic host applications as a service things seem to be working beautifully... as long as we use the IServiceCollection. I…
1
vote
1 answer

Unable to start .NET Core 3.1 Worker Service on Docker using Serilog

I'm writing a .Net Core 3.1 Worker Service application using Visual Studio 2019 (Docker support enabled). If I start the app using Docker all works well but when I add Serilog.AspNetCore 3.4.0 dependency to the project I'm not able to debug with…
E.Benedos
  • 1,585
  • 14
  • 41
0
votes
0 answers

After the Update-DataBase migration command, A database with the same name exists error

After executing the migration command Update-DataBase -v. I get an error. An attempt to attach an auto-named database for file Bookinist.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC…
0
votes
0 answers

IOptions validation error occurs when trying to run a dotnet app

I have built a Discord bot app with C# and I'm trying to run it using dotnet app.dll, but I instantly encounter an error: Microsoft.Extensions.Options.OptionsValidationException: A validation error has occurred. This issue does not happen if I use…
0
votes
0 answers

Best practise for multiple implementations of IHostedService

I have an application which acts as a gateway has two processes in it and they are continuously processing a stream of events. Both of the Processes have start and stop methods on them. They talk to each other via an event queue. public class…
uriDium
  • 13,110
  • 20
  • 78
  • 138
0
votes
1 answer

What is the purpose of IWebHostBuilder.PreferHostingUrls

I know what the documentation says, but I do not know where the IServer gets introduced or how it is configured. My specific case is that I am calling IHostBuilder.ConfigureWebHost (not ConfigureWebHostDefaults), which as best I can determine does…
0
votes
1 answer

ConfigureContainer in .NET Core 3.1 Generic Host implementation

I am trying to migrate our framework project to .NET Core 3.1. As part of the migration, I am trying to register modules via ConfigureContainer method provided by the GenericHost. This is what I have: Host.CreateDefaultBuilder(args) …
0
votes
2 answers

"Microsoft.Extensions.DependencyInjection" and different concretes per environment

"Microsoft.Extensions.DependencyInjection" List of "environments" Production Uat Qa DevShared LocalDev With DotNet (Framework/Classic) 4.6 or above (aka, "in the past", I used "Unity" with xml configuration. …
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
1
2