Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Surprise T Rex
Apr 9, 2008

Dinosaur Gum
If not, try deleting the bin/obj folders from your projects. (Clean and rebuild isn't enough, sometimes...)

Are you by any chance using Xamarin Forms?

Adbot
ADBOT LOVES YOU

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
This is possibly a bit of a weird question but I’ve seen it done before in at least one prior job…

Is there a way to check in advance that all interfaces have an implementation registered in the built-in DI?

I want to basically “unit test that everything is registered” since we can’t run our app locally and we keep having pipelines fail or production issues caused by people implementing things and not registering it in DI so injection fails.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Yeah it’s 100% not a great robust idea, but I just wanted a little bit of extra safety. Had a prod issue this afternoon that should have been avoided in a number of ways, and more of a safety net might be nice.

We do have a bunch of “integration” tests that run in the CI pipeline but it just amounts to some Postman requests being sent to each endpoint and checking that nothing explodes. Generally this is good enough but we had a scenario with a Service Bus helper class not being registered, and the service bus stuff doesn’t do anything on non-prod environments for *reasons* I guess.

So nothing ever instantiated that class, meaning it never tried to resolve the missing dependency until runtime.

Most things we use operate using CQRS though so I could probably at least check after Startup that I can instantiate a real implementation of our ICommandHandler<TCommand> for each Type that inherits our base IQuery or ICommand interfaces.

If I verify this stuff in Startup, then at least when the app runs in the pipeline it’ll explode on missing dependencies even if the code path for a given test never actually tries to resolve that specific implementation.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum

Red Mike posted:

How did they test that it was working while developing?

How did the tests pass after development finished?
If the feature was working in non-prod because it didn't actually call any of the service bus logic, and fell over in prod where service bus stuff exists, then that means the service bus stuff is untested.

It’s pretty extensively unit tested, and the entire Azure Function endpoint is integration tested in a test fixture that forgoes any Mocks and uses real instantiated dependencies (except where there are system boundaries e.g. external APIs or DBs in which case the responses from those are mocked).

I think what happened here is that all these tests rely on manually passing dependencies into the class under test - whether Mocked or real ones manually instantiated - thus not relying on DI at all. This, combined with an inability (I’m told?) to run the API locally means it wasn’t tested by just running a manual run through of the happy path.

This place is big on TDD but “lol never ran the app” is a weird consequence of doing things that way.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Yeah, this is an API built out of individual Azure Functions so no ASP.Net controllers to speak of.

As mentioned though, the real issue here is not having infrastructure for testing certain parts of the API on non-prod environments. I'm new to the project so I've sort of accepted it when I've been told it's not possible to run specific bits locally or in an integration environment, but perhaps I should be digging into that more. We have a number of external services we write to that are prod-only which I think is the main limitation, but it's still achievable I expect.

I think I'll still see if I can get a check running on Startup to cover the implementations of anything derived from ICommandHandler<>/IQueryHandler<> as mentioned, since that will at least clue us in if one of those core pieces of logic isn't plumbed together at all. Most of the DI happens in those so it at least covers a lot of ground. It's likely to be quicker than getting the API to a state where we can run it in other environments, but as you say it's not really a guarantee of anything in particular.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Are there any good resources on how people tend to use things like Records/Record Structs, Pattern Matching, and other newer language features in the real world?

Everything I’ve seen so far is just toy examples (“Person(string name)” level stuff), but it’d be cool to see how people are using them to make things nicer.

Semi-related, what are peoples thoughts on stuff like using small private types internally in a class to essentially replace Tuples or anonymous objects? Useful or just noise?

Surprise T Rex
Apr 9, 2008

Dinosaur Gum

ChocolatePancake posted:

I can see the value in returning multiple values from local functions, but I haven't personally run into that use case myself.
It's not so much that I avoid the feature, it's that creating an encapsulating type for all the return values is generally simple and more readable.

I think this is my stance on it too, just stick ‘private record struct ButtFarter’ in front of the tuple declaration and it’s basically done.

I’ve used some of the pattern matching stuff recently to allow me to create a single class that takes an IReport interface and uses type patterns to figure out which of the 4 inconsistent inheritors of reports something actually is and therefore where to find the email address of the person we should send it to, but I feel that’s just using a nice feature to paper over inconsistencies in the design where adding a real interface would be a much better solution (but harder because of the number of weird duplicate-but-slightly-different models that such a change would affect)

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Forgot about this thread but it reappeared at a good time! Anyone know anything about Azure DevOps?

Trying to put a pipeline together that runs all tests, then packages up 6 individual Azure Functions App projects into artifacts, while minimising repeated work (like multiple nuget restores, and building the entire thing only once ideally if we can?)

Currently we have 6 parallel DotNetCLI@2 jobs running to build each function project that all depend on a single test step beforehand, and each does its own restore and build.

This definitely seems possible, but not sure if it’s easy, or if I’m overthinking how much this will actually affect build times?

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
What's the state of the art for creating PDFs in C# code now? Ideally one I can run from a serverless Azure Function or AWS Lambda. At work we do some of this using rendering Razor templates to HTML and feeding it to Puppeteer(?) to basically fake a print-to-PDF, but that requires us to run it as a docker container so we can bundle a headless Chrome with it and that seems like more effort than is necessary.

QuestPDF seems good but new and I'm not sure if I'm just being blinded by it looking semi-modern.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Started setting up a .Net 8 Azure Function to handle my PDF generation stuff as discussed earlier in the thread... and uh, the Azure Functions Deployment Centre option to auto-generate a CI Github Actions workflow doesn't seem to work? It creates the file and sets up the action on my repo, but it doesn't succeed at actually deploying.

It created a workflow file that had a bunch of problems: it had no "contents: read" permission set up so the action had no permission to do anything useful, it seemed to have a step that was trying to login to the az cli using an Microsoft Entra ID client id/secret and that's confusing as hell, so I've replaced that with using the Publish Profile downloaded from the Azure Portal instead, but then the Function resource I created didn't have a Storage Account associated with it (which I didn't think was even possible?), and after creating one and setting the AzureWebJobsStorage app setting to the connection string for it, it's still failing to actually do the zip deploy.

Am I missing something getting this to work? I can't tell if it's me or Azure. Is it just not possible on a free trial Azure account? Maybe it doesn't work with private repos?

Adbot
ADBOT LOVES YOU

Surprise T Rex
Apr 9, 2008

Dinosaur Gum
Is there a good guide to the differences in Application Insights logging between .Net 6 in-process functions and .Net 8 isolated worker functions?

We’ve recently upgraded and now most of our app insights logs are missing fields like Operation_Name which we usually found quite useful.

I feel like we were probably just doing the most :effort: implementation of logging ever if this has torpedoed it this badly, but there’s an absolute mess of guides for App Insights, OpenTelemetry, ASP.Net, .Net, and Azure Functions (both in and out of process models) and I can’t fully make heads or tails of what’s considered best practice.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply