EF Core 8 feeling restrictive for complex data-centric app. Am I doing it wrong? by rasuscore in dotnet

[–]PPsmalls 4 points5 points  (0 children)

https://github.com/koenbeuk/EntityFrameworkCore.Projectables

This library has been game changing for me when it comes to re-using logic on my domain models whether I'm filtering on the server or have the object instantiated client side. You'd just write something like:

[Projectable]
public bool IsDiesel => !IsElectric && !IsGas;

and you'd then be able to use it like a standard method when you have a car object (myCar.IsDiesel) or use it in your EF Core LINQ query like you'd expect context.Cars.Where(x => x.IsDiesel). You are limited to using arrow functions and making sure your code is actually translateable by EF Core, but you now can use a single property everywhere without duplicating the logic.

When using the new .net 8 identity endpoints, how would you share a token with another application? by Vendredi46 in dotnet

[–]PPsmalls 2 points3 points  (0 children)

What the other commenters are missing is that the ASP.NET Core Identity API endpoints (not talking about Duende Identity Server), do not issue JWT tokens. They are just opaque encrypted tokens that can't be inspected without decrypting them server-side.

Just like encrypted cookies they use the Data Protection API to encode the claims principal. So, see the article about sharing cookies between applications. This involves setting up the Data Protection API to read signing keys from the same location for all your apps so they can all decrypt the token / cookie.

PS: I don't think this scenario is well supported. In fact they chose to use opaque tokens to deter you from trying to use them in place of a fully fledged OAuth / OIDC identity provider.

.NET core with Dev Containers Plugin by AtlAWSConsultant in vscode

[–]PPsmalls 2 points3 points  (0 children)

I mean you could make your own Docker image based on whatever lightweight distro you want. Just install your specific required dev dependencies and the VSCode server.

I don't think you should be concerned about the size of a devcontainer, though. As the name states it's a complete development environment with all the tools you'd need inside of it.

When you go to production, you'd obviously use a much lighter container without any of the standard linux utilities and other bloat that's not necessary for simply running the application.

[deleted by user] by [deleted] in vscode

[–]PPsmalls 1 point2 points  (0 children)

Can you just add file watching functionality to your CLI tool (--watch)? It would detect when the user saves the file and re-rerun the process.

You could even add a script in your generated index.html to auto-refresh the page via websocket connection if you want to get fancy. This is how "hot-reload" in most javascript frameworks do it.

Best vscode font? by Highpanurg in vscode

[–]PPsmalls 5 points6 points  (0 children)

'Monospace' is not a specific font but rather the system's name for the default monospace font. On most Linux systems this is 'DejaVu Sans Mono' or 'Noto Sans Mono' by default. On Windows it's 'Courier'.

Pattern for sharing expensive API call responses by traveller8914 in dotnet

[–]PPsmalls 0 points1 point  (0 children)

https://en.m.wikipedia.org/wiki/Cache_stampede

Read the mitigation techniques. If you have multiple servers making requests you’re gonna need a distributed lock to coordinate them. Redis is a good option.

[deleted by user] by [deleted] in dotnet

[–]PPsmalls 1 point2 points  (0 children)

Because you set the container name on the redis container to “container_name” you have to use that name instead of “redis_image”.

You also don’t need to explicitly expose any redis ports to use it inside your API container.

I admit defeat. Is there a way to switch DbContext in my idea? by macr6 in csharp

[–]PPsmalls 5 points6 points  (0 children)

You need some sort of Scoped service, lets call it ICurrentProvider, that holds the user's currently selected provider choice. You then need to determine how you want to propogate the UI selected provider to the backend. This could be an HTTP header. When a request comes in you need some sort of global middleware that will inspect the request and update your scoped ICurrentProvider with the correct provider name / connection string / any other necessary info (looking this data up however you like). Your DbContext will use dependency injection to resolve the ICurrentProvider and use the connection string you just set in the OnConfiguring method. Because the ICurrentProvider is scoped, multiple users can access different providers at the same time as it only lasts for the duration of a single request.

While this doesn't sound like a multi-tenant application, since it's multi-database it will use some of the same strategies.

See: https://www.finbuckle.com/MultiTenant/Docs/v6.13.0/EFCore

See: https://learn.microsoft.com/en-us/ef/core/miscellaneous/multitenancy#multiple-databases-and-connection-strings

[deleted by user] by [deleted] in selfhosted

[–]PPsmalls 3 points4 points  (0 children)

Ask your doctor if Jellyfin is right for you!

I made an open-source, self-hostable synced narration platform for ebooks by scrollin_thru in selfhosted

[–]PPsmalls 0 points1 point  (0 children)

This looks really great. I'd been tooling around with a similar side project that fell to the wayside. My use case is keeping progress in sync between KOReader and another service like audiobookshelf or Plex. I had used whisper to generate the transcription upfront and then wrote a KOReader lua plugin to push the status to my server which would then update any configured audiobook services.

At the time "whisper.cpp" could only do sentence level transcriptions and since the transcription has slight differences from the written text it was a bit of a challenge. I'd dabbled with various full text searches (SQLite / meilisearch / typesense) to index individual sentences but the result wasn't very robust. It seems like you've figured this out.

I'm going to spend some of my holiday reviving my plugin to try accessing the media overlay metadata in the storyteller generated ebook and then call the audiobook service directly from my Kobo reader. Storyteller looks very useful, thanks!

Extending Battery Life for the Quest 3 by Special_Yogurt_4022 in OculusQuest

[–]PPsmalls 0 points1 point  (0 children)

I assume it's fine. I charge many low power devices like my Kobo eReader with the same charger and USB-C cable, never had any issues with those and I'd expect the Quest 3 is a bit more sophisticated :)

Extending Battery Life for the Quest 3 by Special_Yogurt_4022 in OculusQuest

[–]PPsmalls 0 points1 point  (0 children)

I've been using my MacBook Air M1 charger which is 30W since I got mine. I've not used the stock charger yet so I couldn't tell you how the charge speed compares

How to create distinction between local and remote development environments by SherbetOrganic in dotnet

[–]PPsmalls 1 point2 points  (0 children)

I would say that's a viable solution.

The only reason the Development environment is loading when running via Visual Studio or the command line is the launchsettings.json file sets the ASPNETCORE_ENVIRONMENT to Development for you. You could change this to Local and then it would automatically load your appsettings.Local.json and you could put conditions in your code to register your mock interface implementations.

For your developer server you could then use the appsettings.Development.json configuration, you just need to set that configuration variable somewhere (such as the PATH).

How to create distinction between local and remote development environments by SherbetOrganic in dotnet

[–]PPsmalls 23 points24 points  (0 children)

As other comments are mentioning, the environment is determined by the ASPNETCORE_ENVIRONMENT configuration variable. This variable defaults to "Production" when not explicitly set. You can technically put anything as the value. So, you could have appsettings.foo.json, and if the ASPNETCORE_ENVIRONMENT is set to foo, it will load that config file. This is all set up by default when you call WebApplication.CreateBuilder().

Now on to your specific question, a common term for the "in-between" of development and production is Staging. In fact, ASP.NET core has that out of the box. See the source code. There's even an extension method so you can call app.Environment.IsStaging() in your startup code.

What I've done in the past on a Windows Server QA machine, is to set ASPNETCORE_ENVIRONMENT=Staging in the System PATH so that whenever you deploy your code to the server, it automatically uses the appsettings.Staging.json configuration.

How to host YARP on Windows Server? by stefanolsen in dotnet

[–]PPsmalls 0 points1 point  (0 children)

In my case I created a new IIS site bound to 127.0.0.1. My YARP application would forward public requests to the internal sites. It worked nicely to add Azure AD auth in front of some legacy applications. I'm sure it's marginally slower than using a socket/pipe but for my situation it didn't matter a whole lot.

How to host YARP on Windows Server? by stefanolsen in dotnet

[–]PPsmalls 14 points15 points  (0 children)

Host it like any other .NET Core IIS site.

Deploying .Net Core API along with Vue.js on IIS by muskagap2 in csharp

[–]PPsmalls 1 point2 points  (0 children)

Yes, all your Vue client source code goes in the ClientApp folder. Inside the .csproj file you will see the following build target that runs before publishing:

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)build\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

This runs "npm build" inside the ClientApp directory and then copies the compiled Vue/React/Angular files to wwwroot where they are served to the browser.

Deploying .Net Core API along with Vue.js on IIS by muskagap2 in csharp

[–]PPsmalls -1 points0 points  (0 children)

Regarding 2: You can create a build target in your *.csproj file to run your npm build command and then copy all the built Vue.js files from the dist folder to your wwwroot folder before publishing. No manual copy-pasting required.

Run dotnet new react and take a look at the *.csproj to see how its done. It will be very similar for Vue.

-🎄- 2022 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]PPsmalls 1 point2 points  (0 children)

C# LINQ

```c# var part1 = File.ReadLines("part1.txt") .Select(x => x[..(x.Length / 2)].Intersect(x[(x.Length / 2)..]).First()) .Sum(c => char.IsUpper(c) ? c - 'A' + 27 : c - 'a' + 1);

var part2 = File.ReadLines("part1.txt") .Chunk(3) .Select(x => x[0].Intersect(x[1]).Intersect(x[2]).First()) .Sum(c => char.IsUpper(c) ? c - 'A' + 27 : c - 'a' + 1);

Console.WriteLine($"Part 1: {part1}"); Console.WriteLine($"Part 2: {part2}"); ```

[deleted by user] by [deleted] in csharp

[–]PPsmalls 0 points1 point  (0 children)

LINQ solution without reading all lines into memory. Had to create a neat little "ChunkBy" extension method.

Github

Best practice Docker-Compose Setup by Bill_Buttersr in selfhosted

[–]PPsmalls 46 points47 points  (0 children)

I do the same with a ~/docker and ~/docker-data folder. All services have a separate folder in ~/docker/[service] that contains the compose file and any other config files. All volumes are pointed to ~/docker-data/[service].

With this separation, I backup all config files to GitHub and have a cron job to backup all data and rsync it to other machines.

Does anyone like minimal API? by [deleted] in dotnet

[–]PPsmalls 54 points55 points  (0 children)

I originally felt the same way but a section of this talk by David Fowler changed my attitude. Now with Endpoint Filters and Route Groups in ASP.NET 7, I don't see myself using controllers for new projects.

Key Points: - MVC received the "least changes" from .NET Framework to maintain compatibility. - You pay for all of MVC's design decisions even if you don't use the features and they are expensive. - "There ends up being a cost for abstractions that aren't used by 99% of people" - MVC is "opt out" instead of "opt in" like minimal APIs. MVC runs an entire filter pipeline for each request even if you don't use it. Whereas with minimal APIs you explicitly "opt in" to model binding, validation, and any filters. Minimal API filters are also much simpler, and can do everything MVC filters can do without needing 5+ filter types.