Running Temporal Worker and Workflow and activities inside a single .NET Web Api without seperate Worker

So it’s definitely a good idea to do DB stuff in activities. But now I realize your original question is about whether the worker should be in the same process as the web app. Usually you want it separate because workers scale differently than web applications, but you can keep it in the same if you want. That doesn’t mean the worker can’t use the same DB as the web app.

No, app.Run(); blocks. If you must colocate these, you’ll want something like the hosting extension and attach to the same builder. So before builder.Build() have something like:

using Temporalio.Extensions.Hosting;

// ...

builder.Host.ConfigureServices(ctx =>
    ctx.AddHostedTemporalWorker(
        clientTargetHost: "localhost:7233",
        clientNamespace: "default",
        taskQueue: MyWorkflow.TaskQueue).
    AddWorkflow<MyWorkflow>());

But you usually don’t want to share web app process and worker process (see this ASP.NET sample).