question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Finbuckle implementation on Worker Service (.Net Core 3.1)

See original GitHub issue

Can I just start by saying I absolutely love this library, I use it for one of my APIs and it works a treat.

I am now tying to configure a worker service as it’s own project and I want it to connect to different SQL Server databases using Finbuckle and EF Core. I have configured everything to the best of what I can, but I note that as I don’t have a Startup file and there is no middleware as I am not dealing with a request pipeline. Where do I need to add app.UseMultiTenant()? Alternatively is there a way I can pass a TenantInfo I obtained from a Configuration Store / Worker activity Directly to a dbcontext as part of a worker task?

Here is an extract from Program.cs code for the worker service

public static IHostBuilder CreateHostBuilder(string[] args) =>
                Host.CreateDefaultBuilder(args)
                .ConfigureLogging((context, logging) => {
                        logging.AddSerilog();
                    })
                .ConfigureAppConfiguration((hostContext, config) =>
                {
                   code to obtain configurations
                })
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddMultiTenant()
                            .WithStaticStrategy("dev")
                            .WithConfigurationStore(hostContext.Configuration, "FinbuckleSection");
                    services.AddDbContext<AppContext>();
                    services.AddHostedService<Worker>();
                });

This is currently throwing a null reference exception for Connection String in the EF Core context which is inheriting from MultiTenantDbContext , and overriding OnConfiguring. This makes sense to me as at no point have I been able to pass the TenantInfo for a Worker Service task.

Thanks

H.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewTriesToCodecommented, Sep 21, 2020

hi @hhuseyinpay

I think this will work. I think it will run nonstop though – you might want to put it on a timer as described here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio#timed-background-tasks

Also you might want to include the look that sets up the tenantRepo list inside the timed while look so it picks up any updates to the tenant in the tenant store.

I’m not sure exactly if the lessions and servers items work as you intend since that’s specific to your app, but overall look good!

0reactions
hhuseyinpaycommented, Sep 20, 2020

My final solution is: Screen Shot 2020-09-20 at 19 22 49

It seems working for now but I don’t know what happens for the long-running. Any suggestion?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Finbuckle.MultiTenant
This introduction assumes a standard ASP.NET Core use case, but any application using .NET dependency injection can work with the library. Installation. First, ......
Read more >
Multitenancy in ASP.NET Core - Simplest Way to achieve ...
In this article, let's learn how to implement Multitenancy in ASP.NET Core in a rather simple way making use of Entity Framework Core....
Read more >
Worker Service in .NET Core 3.1 | Wake Up And Code!
The quickest way to create a new Worker Service project in Visual Studio 2019 is to use the latest template available with .NET...
Read more >
Get a Head Start Developing Multitenant SaaS Cloud ...
This article serves as a complete guide to creating a multitenant SaaS cloud application using ASP.NET Core and Microsoft Azure.
Read more >
Worker Services - .NET
Learn how to implement a custom IHostedService and use existing implementations in C#. Discover various worker implementations, templates, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found