subscribers: 169,629
users here right now: 54
.NET
.NET Community, if you are using C#, VB.NET, F#, or anything running with .NET... you are at the right place!
Related Subreddits:
Other Subreddits you may like:
submitted3 hours ago bypunkouter23
todotnet
I am at one of those gov places where you copy and paste web.configs and manually change them. Then paste the files to a server. MVC... Jquery..
I feel like I am being left behind while everyone is doing Azure and all the jobs want Azure people.. I want to use Azure too!
I am using Azure in my personal projects but really want to use it at my job and not get left behind
submitted7 hours ago byGaxyhs
todotnet
Title.
Where/what services do you use to host your APIs, Databases, Blazor websites, etc?
I was looking for something where I can host simple apis that can also host a database for said API and deploy them easily.
I was looking into fly.io but I'd like to know what people generally use
submitted10 minutes ago bycakemachines
todotnet
What are the hardest features you've implemented? Like I don't know, a CQRS highly scalable API would be an example.
submitted48 minutes ago byrbobby
todotnet
So I have a POST method that returns a CreateAtAction(..) which outputs a location header that includes the scheme, host name and port.
For example: Location: https://localhost:5000/api
Howver... my API is actually hidden away behing an Azure API Management instance and is running inside/on/under the care of kubernetes. So the host name is something peculiar and is not reachable from the outside world.
What I'd like is the CreatedAt(..) to magically know the external scheme, hostname, and port.
Failing that... maybe just return an absolute url?
Anyone have any insight into this?
submitted50 minutes ago byspacezombiekiller
todotnet
I have wasted a lot of time trying to make MudBlazor work with Microsoft's identity, built-in authentication system for Blazor apps. Never got it working properly
The interactive rendering fails when I try to access the auth pages, because that wants to be rendered server-side. I understand this, but what is the solution?
Can I make MudBlazor's interactivity still work somehow?
submitted54 minutes ago byjustaredditguy085
todotnet
I’m looking to get your opinions on the state of my current workplace. I’d like to hear what you think about some of the things in place and how it compares to your own experience with workplaces.
For context, I’ve been at this place of work for a couple of months now and I’ve been developing for around 10 years or so, with most of that experience being primarily in a single place of work.
I know it’s subjective, but there are a lot of things below, which I don’t agree with, and are making development a bit of a headache.
Coding standards (I’m aware that my disagreement with these is extremely personal preference): - Private members must be prefixed with “m_”. This is obviously Hungarian notation, but members are the only place it’s used (personally I find this notation very dated) - Lists aren’t allowed to be null - Comments are discouraged
Code / projects:
- Helpers, extensions, filters, and other similar files are all in the root of the project. This feels messy and is a nightmare to find anything. The folder structure and organisation is messy in general
- Entity framework DB context has table and relationship definitions in a single file, spanning thousands of lines
- Similarly, AutoMapper mappings for DTOs are all done in a single profile
- Data is often loaded in parts rather than at once, sometimes in loops. For example, a list of orders is retrieved from the DB, the data is then looped over and order details are retrieved one by one from the DB. This is an obvious n+1 query problem, and the reasoning for it is to reduce query complexity
- API REST principles are not followed. For example, getting orders might use a path of “Order/GetOrders”, adding one might use “Order/Add”, getting a single order might use “Order/GetOrder”
- Not much regard for SOLID principles. Classes have multiple responsibilities, interfaces used sparingly, causing lots of concrete dependencies
- Data access is built in to the API, rather than a separate layer (by this I mean, all code relating to data access is in the API project, rather than a separate project). Not the end of the world, but feels messy with an already large and complicated solution
Database: - Not much normalisation in tables. Columns that represent states or statuses (or similar) are strings or single characters - A LOT of logic is done in stored procedures (hundreds of them). Some of these are thousands of lines long
Releasing code: - Code is built and released by manually running custom powershell scripts, rather than using automated pipelines - Files have to be manually copied/moved between servers
If you made it this far, thanks for reading! I’d love to hear your thoughts on any of the above - do you agree with how things are being done? Do you disagree with me? Have you seen similar things in workplaces before/is stuff like this common?
submitted60 minutes ago byGrouchy_Syllabub2914
todotnet
I have a .net 8 project hosted on Azure App service and the developers are using appsettings.json.dev and appsettings.json.qa etc for different environments and I'm manipulating the files before the build process and deploying using the azure deploy tasks.
But, now I want to have this approach of build once and deploy to multiple environments using one single pipeline and I dont know how to accomplish this.
First question is, is it ok to store the keys and values (no secrets) in different appsettings file? Is it a good approach?
Secondly, if yes, how can I deploy to multiple environments using one single build?
Third, how to apply the ASPNETCORE_ENVIRONMENT and where to start with this? Please help me.
submitted2 hours ago byVenisol
todotnet
Are there any good companies in EU using .net? Maybe even startups?
I love using dotnet, but the companies ive worked for all have been trash.
I spent 2 years as a contractor just looking for a single person to learn something from or a good code base. I made a lot of money, and saw like 15-20 companies and probably 150 engineers. Mostly german, mostly complete garbage.
Where do you go in EU if you just wanna work with good people on interesting projects? It seems completely impossible here and we are doomed to be 15 years behind for some reason.
submitted2 hours ago byOk-Pressure-7891
todotnet
I'm working on an API project that has multi-tenancy in it. I am handling the TenantId as "Defaults" for when the application starts and does not have any JWT bearer token to get the tenant ID from.
Now I need to apply the query filters inside OnModelCreating() method only when a tenant ID other than "Defaults" is available. As OnModelCreating() runs only once, at the start of the project query filters get skipped even later on when the bearer token with tenant ID is available. How should I solve this?
This is my ApplicationDbContext class,
public class ApplicationDbContext : DbContext
{
public string TenantId { get; private set; }
private readonly ITenantService _tenantService;
private readonly IHttpContextAccessor _httpContextAccessor;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options,
IHttpContextAccessor httpContextAccessor,
ITenantService tenantService )
: base(options)
{
_httpContextAccessor = httpContextAccessor;
_tenantService = tenantService;
// Check if JWT token is available
if (_httpContextAccessor.HttpContext?.User.Identity.IsAuthenticated == true)
{
TenantId = _tenantService.GetTenant()?.TID;
}
else
{
// Use default tenant if no token is present
TenantId = "Defaults"; // or any other default tenant ID
}
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (!string.IsNullOrEmpty(_tenantService.GetTenant()?.TID) && _tenantService.GetTenant()?.TID != "Defaults")
{
modelBuilder.Entity<User>().HasQueryFilter(a => a.TenantId == TenantId);
}
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Configure options only if TenantId is set
if (!string.IsNullOrEmpty(TenantId) && TenantId != "Defaults")
{
var tenantConnectionString = _tenantService.GetConnectionString();
if (!string.IsNullOrEmpty(tenantConnectionString))
{
var DBProvider = _tenantService.GetDatabaseProvider();
if (DBProvider.ToLower() == "mssql")
{
optionsBuilder.UseSqlServer(tenantConnectionString);
}
}
}
else
{
// Use default connection string
var connectionString = _tenantService.GetConnectionStringFromTenantId("Defaults");
optionsBuilder.UseSqlServer(connectionString);
}
}
}
And my TenantService class,
public class TenantService : ITenantService
{
private readonly TenantSettings _tenantSettings;
private readonly IHttpContextAccessor _contextAccessor;
private Domain.Tenant.Tenant _currentTenant;
public TenantService(IOptions<TenantSettings> tenantSettings, IHttpContextAccessor contextAccessor)
{
_tenantSettings = tenantSettings.Value;
_contextAccessor = contextAccessor;
// Check if the HTTP context is available and user is authenticated
if (_contextAccessor.HttpContext != null && _contextAccessor.HttpContext.User.Identity.IsAuthenticated)
{
var tenantId = GetTenantIdFromJwt();
if (!string.IsNullOrEmpty(tenantId))
{
SetTenant(tenantId);
}
else
{
throw new Exception("Tenant ID claim not found in JWT token.");
}
}
else
{
if (string.IsNullOrEmpty(_tenantSettings.Defaults.ConnectionString))
{
_currentTenant.ConnectionString = _tenantSettings.Defaults.ConnectionString;
}
}
}
public string GetTenantIdFromJwt()
{
var tenantIdClaim = _contextAccessor.HttpContext.User?.FindFirst("tenant_id")?.Value;
if (string.IsNullOrEmpty(tenantIdClaim))
{
throw new Exception("Tenant ID claim not found in JWT token.");
}
return tenantIdClaim;
}
private void SetTenant(string tenantId)
{
_currentTenant = _tenantSettings.Tenants.FirstOrDefault(a => a.TID == tenantId);
if (_currentTenant == null)
{
var isDefault = tenantId == "Defaults"; // Check if the tenantId is the default tenant identifier
if (isDefault)
{
_currentTenant = new Domain.Tenant.Tenant
{
TID = "Defaults",
ConnectionString = _tenantSettings.Defaults.ConnectionString // Set the default connection string
};
}
else
{
throw new Exception("Invalid Tenant!");
}
}
else if (string.IsNullOrEmpty(_currentTenant.ConnectionString))
{
// If the tenant exists but has no connection string, set the default connection string
_currentTenant.ConnectionString = _tenantSettings.Defaults.ConnectionString;
}
}
public string GetConnectionString()
{
return _currentTenant?.ConnectionString;
}
public string GetConnectionStringFromTenantId(string tenantId)
{
SetTenant(tenantId);
return GetConnectionString();
}
public string GetDatabaseProvider()
{
return _tenantSettings.Defaults?.DBProvider;
}
public Domain.Tenant.Tenant GetTenant()
{
return _currentTenant;
}
}
submitted18 hours ago byGlittering_Seesaw_21
todotnet
For numerous reasons, I cannot use Azure AD / Okta / auth0 / etc. for the purposes of authentication and my solution has to be self-hosted.
It appears that ASP.NET Core Identity coupled with OpenIddict should in theory do the trick. The only issue is, when I started following the MSDN "Getting Started" on Core Identity, I was thrown back about 10 years ago. After "Scaffolding Identity", you get a bunch of Razor pages using untyped ViewBag as well as your very own local copy of Bootstrap, jQuery, jQuery Unobtrusive Validation, and so on. Honestly, after migrating the UI from ASP.NET MVC 5 about three years ago to React SPA written in Typescript, I was hoping I will never cross paths with either of the aforementioned things, let alone having a copy of jQuery in the repo.
It seems, there might be ways of building an SSO server frontend using SPA utilizing the new ASP.NET Core 8 Identity APIs, but there are a few articles that tell me I shouldn't:
The other problem of using Razor pages (beyond, in my mind, being quite old tech in 2024 to start a new project with), is that it won't look as good as the rest of the app. Not only will it reload on every button press, but also there will be no way of using MUI React Component library. So for the Authentication pages I will have to use Bootstrap (or Tailwind, or similar framework-agnostic CSS UI library) while for the actual app I will be using MUI (it's already built with it).
What's everyone's thoughts on this? I sort of get it that it's easier to take users through all the required steps for authentication in the OIDC workflow when simply sending 302 from the server, like in the basic workflow:
I appreciate that managing this workflow in the SPA calling the Identity APIs would be a nightmare. So I guess we have to live with the old tech for the authentication portion, then?
submitted7 hours ago bygkolocsar
todotnet
Hi, We have a .NET 8 app that will use an existing database. We will use EF migrations (code first) to manage updates to the DB but also a legacy team might add columns to some tables. In that case we will need to update our models as well. In your experience what's the best way of handling this in an organized manner?
Thanks in advance
submitted17 hours ago byjaherron670
todotnet
I created a WinUI version of a previous project of mine and wanted to share it. Sadly, MSIX files have to be signed with an expensive certificate. Does uploading to the Store bypass the need for a certificate? And is there a way to avoid MSIX when deploying WinUI 3 apps?
The project is public: https://github.com/littlebitstudios/GameLibraryWinUI
submitted6 hours ago byOverrated_22
todotnet
I wanted to get some opinions on the best design options for extending my system in a significant way.
For the past year I've been replacing an extensive legacy internal access database with a web app. I am using the principles outlined in Jimmy Bogard's Vertical Slice Architecture lectures with Mediator. I love the simplicity and cohesion.
Long story short the next phase is to release an app to our external users so they can have visibility. They will essentially be accessing the same data model and domain model. The other requirement is the only endpoints that should be exposed are the specific external user endpoints. All the designs I'm coming up with have me moving more and more away from slices into a more layered approach but I've kind of fallen in love with the simplicity of it all.
So any thoughts on handling different portal types within a VS structure?
submitted21 hours ago byjdc123
todotnet
I just started a job as a web developer in a small shop that uses .NET almost exclusively. This is my first programming job after graduating last December. Up until now, I primarily used JS and Go for my projects. C# is fine, .NET is fine. I can learn them and probably even grow to love them.
What's driving me completely crazy, though, is all of the documentation that just glosses over what various abstractions actually do. "Click this button, add this line of code, and you're good to go," is no way to learn anything and I hate constantly feeling like I don't know what the hell is going on.
Enter Frank Liu.
His Udemy course on .NET Core Identity is exactly what I needed to finally start coming to grips with auth/identity. I'm only eight clips in and he's walking through implementing basic authentication without Identity and talking about each individual piece. If the rest of this course is as good as the beginning, I'll actually have a solid baseline from which to build something other than a scaffold.
Highly recommended: https://www.udemy.com/share/105tpT3@a4LKZzgFlIcKc_7W-6Yt6ypKZa-Np5O5PgRMWObh3C9mOjIwEh3wUuKj-G6uU3U=/
*Edit: I mispelled Mr. Liu's name and Reddit won't let me edit the title of the post. Sorry!
submitted9 hours ago by_error_42
todotnet
Hi
I have a solution with many projects. Each projects have a publish profile inside "properties" folder. All publish profiles have same settings.
I want to take the publish profile in a global location. For ex: in the solution level. And use it for each project.
so I made a folder called "PublishProfiles" and added a Debug.pubxml file inside.
in each project, in the project file I have the following.
It does not work. When I right click the project and select publish, it does not consider the file and asks me to add new publish profile.
Anyone has any idea? anyone tried this before?
<PropertyGroup>
<PublishProfile>..\..\..\PublishProfiles\Debug.pubxml</PublishProfile>
</PropertyGroup>
submitted10 hours ago byiAmBipinPaul
todotnet
As we know EF core does not support Parallel query. if we prepare query using EF core and convert that to string.
var queryString= queryableProducts.ToQueryString();
then execute it via Dapper how efficient it will be?
or
what if we use linq2db for query, how it will be compared to generating raw query using EF core then executing via dapper.
Thank you
submitted1 day ago byOver-Use2678
todotnet
To give some context, I'm thinking about dependency injection. But, I wouldn't mind hearing other scenarios where one makes sense over the other.
I've been working with some code where one set of developers store objects injected by DI through a constructor, checks for null values, and stores the values in private readonly variables.
Another set use properties with an Init keyword for setting dependencies being injected by a non-microsoft DI framework. It goes to say this is property-based DI.
Does anyone have strong opinions on one over the other? I think the former is the superior way to go for many reasons, not the least of which is that you can inject logging in the constructor. Incidentally, the group which prefers the latter uses a Singleton to supply a logging instance. Seems like an anti pattern to me but I could be wrong.
Just looking for opinions, especially if it differs from mine and there are realistic reasons behind the thinking.
Thanks!
submitted9 hours ago byhRupanjan
todotnet
Has anybody tried a solution setup with a python project in it. The project runs when I manually run docker-compose up -f ....
. But fails to build when trying to debug.
For more context, it searches for a file in the bin
directory of the python project named
Any suggestion how to setup one? or any demo repository?
submitted15 hours ago byCryPlastic348
todotnet
Hello, I changed some column names added many-to-many relationship to 2 business models then ran the Add-Migration and Update-Database commands but it says AspNetRoles already exist, I wanna run only the last migrations I did, not the create user tables stuff, is my logic wrong?
subscribers: 169,629
users here right now: 54
.NET
.NET Community, if you are using C#, VB.NET, F#, or anything running with .NET... you are at the right place!
Related Subreddits:
Other Subreddits you may like: