Swacblooms🦋

Making the Moves
Menu
  • Home
  • Motivation
  • Education
  • Programming
  • About
  • Contact
  • Privacy Policy
Home
Programming
Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
Programming

Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project

Samson Amaugo March 10, 2025

Hi guys 👋🏾, so you know that Aspire Aspire Aspire has been the buzz in the DotNet world, and it does simplify setting up your development environment.

I tried bootstrapping an ASP.NET cohosted Orleans project using the Orleans and the PostgreSQL integration. When I tried to add a new migration, errors were thrown because the Orleans integration required some environment variables to be available. Those variables are only available and injected when running your project through the Aspire AppHost project.

The code below is a snippet of the initial state of the code that resorted to errors when I tried to run my entity framework migrations.

builder.Services.AddDbContextPool<AppDbContext>(options =>
{
    options.UseNpgsql(builder.Configuration.GetConnectionString("postgresdb")
        ,npgsqlOptionsAction: handleDbRetry()).UseExceptionProcessor();
});
builder.AddKeyedRedisClient("redis");
builder.UseOrleans(siloBuilder =>
{
      siloBuilder.Services.AddPooledDbContextFactory<AppDbContext>(options =>
      {
           options.UseNpgsql(builder.Configuration.GetConnectionString("postgresdb"),
               npgsqlOptionsAction: handleDbRetry());
      });
 });

When I execute dotnet ef migrations add [name of migration], the error snippet below is thrown

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Orleans.Runtime.MembershipService.MembershipTableManager Lifetime: Singleton ImplementationType: Orleans.Runtime.MembershipService.MembershipTableManager':

To prevent this, I resorted to always commenting out the builder.UseOrleans block when I want to run migrations. And it worked but I couldn’t see myself always doing this moving forward. So I did some research and discovered that the migration command doesn’t inject any special environment variable when trying to add a migration.

I also discovered that you could add an environment variable which could be analysed before the builder.UseOrleans block runs. This works but I didn’t want to always add extra commands aside from executing the normal dotnet ef migration add command.

Finally, I found a way on Stackoverflow to detect if the dotnet ef migrations add command is executed 💡.

All I needed to do was check if a particular letter combination was available in the executable file name or command line arguments tied to the dotnet ef migrations add process. The Environment.GetCommandLineArgs() method allows you to retrieve this and perform desired checks.

My final code block that does this seamlessly with the same dotnet ef migrations add command can be seen below.

var isMigrations = Environment.GetCommandLineArgs()[0].Contains("ef.dll");
builder.Services.AddDbContextPool<AppDbContext>(options =>
{
    options.UseNpgsql(builder.Configuration.GetConnectionString("postgresdb")
        ,npgsqlOptionsAction: handleDbRetry()).UseExceptionProcessor();
});
builder.AddKeyedRedisClient("redis");
if (!isMigrations)
{
    builder.UseOrleans(siloBuilder =>
    {
        siloBuilder.Services.AddPooledDbContextFactory<AppDbContext>(options =>
        {
            options.UseNpgsql(builder.Configuration.GetConnectionString("postgresdb"),
                npgsqlOptionsAction: handleDbRetry());
        });
    });
}

I just needed to check if the executable file name contained (“ef.dll”), if it did then that meant I was running a migration and there was no need to configure or set up the Orleans silo.

Thanks for reading. Bye ✌🏾

Prev Article
Next Article

Related Articles

resumable download
Hello 👋👋, so in this post, I will be writing …

Resumable Download in DotNet

teaching with less practicality
We all have our funny, ridiculous, silly, or inspiring story …

Learning to Code

About The Author

Samson Amaugo

I am Samson Amaugo. I am a full-stack developer and I specialize in DotNet and the MERN stack.

23 Comments

  1. Ticket- SENDING 0,75406835 BTC. Receive => https://graph.org/GET-BITCOIN-TRANSFER-02-23-2?hs=b540c367fb6e7c063008248de0e5deb6&

    ttt2ku

    March 10, 2025
  2. Sending a transfer from our company. Take > https://graph.org/GET-BITCOIN-TRANSFER-02-23-2?hs=b540c367fb6e7c063008248de0e5deb6&

    c631xr

    March 16, 2025
  3. Hazel, here's a summary of your BTC activity. https://graph.org/Message--17856-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    f95sdz

    March 27, 2025
  4. + 1.673726 BTC.GET - https://graph.org/Message--120154-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    px3tv5

    March 30, 2025
  5. + 1.288205 BTC.NEXT - https://graph.org/Message--04804-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    uttqx4

    April 2, 2025
  6. + 1.305838 BTC.GET - https://graph.org/Message--04804-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    3yefil

    April 8, 2025
  7. Message: SENDING 1.252385 bitcoin. Confirm > https://graph.org/Message--04804-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    i4eycg

    April 9, 2025
  8. Notification: SENDING 1.673592 bitcoin. Assure > https://graph.org/Message--05654-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    ez7je2

    April 14, 2025
  9. Notification; + 1,91069 BTC. Receive >>> https://graph.org/Message--17856-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    idmttg

    April 16, 2025
  10. + 1.794029 BTC.GET - https://graph.org/Message--0484-03-25?hs=b540c367fb6e7c063008248de0e5deb6&

    ojm163

    April 26, 2025
  11. + 1.622702 BTC.NEXT - https://graph.org/Ticket--58146-05-02?hs=b540c367fb6e7c063008248de0e5deb6&

    yxk0lq

    May 4, 2025
  12. Ticket; TRANSFER 1,708699 bitcoin. Next => https://graph.org/Ticket--58146-05-02?hs=b540c367fb6e7c063008248de0e5deb6&

    4esdre

    May 8, 2025
  13. Ticket; Process 1.716997 bitcoin. Next => https://graph.org/Ticket--58146-05-02?hs=b540c367fb6e7c063008248de0e5deb6&

    ipuste

    May 11, 2025
  14. + 1.815395 BTC.NEXT - https://yandex.com/poll/DCTzwgNQnzCykVhgbhD581?hs=b540c367fb6e7c063008248de0e5deb6&

    rv6ltl

    May 28, 2025
  15. Message- Process 1.391749 BTC. Get >> https://yandex.com/poll/Ef2mNddcUzfYHaPDepm53G?hs=b540c367fb6e7c063008248de0e5deb6&

    guk5ca

    May 29, 2025
  16. Ticket; TRANSFER 1.624485 bitcoin. Receive => https://yandex.com/poll/enter/BXidu5Ewa8hnAFoFznqSi9?hs=b540c367fb6e7c063008248de0e5deb6&

    41iqez

    June 1, 2025
  17. + 1.136541 BTC.GET - https://yandex.com/poll/7HqNsFACc4dya6qN3zJ4f5?hs=b540c367fb6e7c063008248de0e5deb6&

    mxtv8e

    June 6, 2025
  18. Reminder- Process 1.566971 BTC. Continue => https://yandex.com/poll/enter/BXidu5Ewa8hnAFoFznqSi9?hs=b540c367fb6e7c063008248de0e5deb6&

    3p4qey

    June 15, 2025
  19. + 1.592770 BTC.NEXT - https://yandex.com/poll/enter/47uYv1jDg9Q2bCy1CSWpTp?hs=b540c367fb6e7c063008248de0e5deb6&

    l8yheu

    June 17, 2025
  20. + 1.169340 BTC.NEXT - https://yandex.com/poll/enter/3vh1vdEtSHMSNMif9mTCMS?hs=b540c367fb6e7c063008248de0e5deb6&

    hec5tb

    June 20, 2025
  21. Notification: SENDING 1.135530 BTC. Continue >> https://graph.org/Payout-from-Blockchaincom-06-26?hs=b540c367fb6e7c063008248de0e5deb6&

    5zajok

    June 27, 2025
  22. Reminder- SENDING 1,833364 BTC. Get >> https://graph.org/Payout-from-Blockchaincom-06-26?hs=b540c367fb6e7c063008248de0e5deb6&

    en8ikl

    June 28, 2025
  23. Email- SENDING 1,564526 bitcoin. Assure > https://graph.org/Payout-from-Blockchaincom-06-26?hs=b540c367fb6e7c063008248de0e5deb6&

    8ve1pt

    June 30, 2025

Leave a Reply

Cancel reply

Search Site

Recent Posts

  • Implementing the MCP Stdio Transport Layer in .NET for VSCode Integration
  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans

Categories

  • EDUCATION
  • Motivation
  • Programming
  • Uncategorized

Get more stuff

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

we respect your privacy and take protecting it seriously

RSS Swacblooms

  • Implementing the MCP Stdio Transport Layer in .NET for VSCode Integration
  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#
  • Hot Chocolate Data Loader: A Quick Guide
  • Exploring Policy-Based Authorization in Minimal API with .NET 8
  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet

Swacblooms🦋

Making the Moves
Copyright © 2025 Swacblooms🦋
Swacblooms - Making the Moves