|
For where it goes, you usually put all that configuration and registration in your main assembly where it will execute once on application startup, somewhere sane people don't unit test. In a WPF application, that might be an overridden Application.OnStartup(StartupEventArgs). You very probably do not want to put it in the constructor of a viewmodel, since that's not a viewmodel's responsibility, and it makes that viewmodel less testable.
|
# ¿ Jul 25, 2019 02:24 |
|
|
# ¿ May 17, 2024 18:32 |
|
A big one is that classes don't inherit interface members (they implement them). That means to use a default implementation, you have to cast an instance of the class to the interface, similar to how you'd use explicitly implemented interface members.
|
# ¿ Aug 19, 2019 10:55 |
|
I don't think even MS-authored libraries pay attention to that guidance.
|
# ¿ Nov 3, 2019 23:50 |
|
TooMuchAbstraction posted:I'm getting an error at the Add statement in Subscribe: "cannot convert from System.Action<T> to System.Action<PubsubEvent>". Which is strange, because the function has a constraint on it that T must be a PubsubEvent. Any idea what's going on here? The type parameter of Action<T> is contravariant, not covariant (i.e. you may assign an instance of Action<TBase> to a variable of Action<TDerived>, but not the other way around). Read more about this here. Without saying anything about your design, to get this to compile, store the delegates as plain objects and cast them to Action<T> in your Publish method.
|
# ¿ Nov 20, 2019 23:16 |
|
TooMuchAbstraction posted:Thanks! Jabor gave a similar response in the General Programming thread. It's unfortunate, but the type-unsafety is kept to a small part of the code so I guess I can live with it. Without knowing more, there doesn't seem to be a need for any of PubSub's members to be static. Storing your state in an instance of your service would let the programmer decide how global that state should be, and it would be easier to test. Having a delegate object be the identity of a subscription is a little suspect, especially when you're storing them in a HashSet<>. You'll need to be conscious of delegate equality and think about edge cases.
|
# ¿ Nov 21, 2019 06:36 |
|
This blog post came out last month, and it's good reading if you have any interest in what ConfigureAwait does.
|
# ¿ Jan 7, 2020 04:49 |
|
Whatever serializer is running there might be expecting a JSON array of numbers.
|
# ¿ May 19, 2020 14:25 |
|
Polio Vax Scene posted:I'm lost and need some guidance. We're building an integration with a third party that uses JWTs to authenticate users. The tokens are signed using an x509 cert. There isn't a way to force the JwtSecurityToken class to add the x5c header. The good (?) news is that JwtHeader is a subclass of Dictionary<string, object>, so you can add the x5c header yourself as an array of strings, and it will be serialized correctly when you turn the token object into a JWT.
|
# ¿ Sep 10, 2020 16:15 |
|
rarbatrol posted:You could wrap the sync method in something like await Task.Run(stuff) or put an await Task.Yield just before it and it may behave a little better for you. await Task.Yield(); might be useful in an environment without a synchronization context, but here, if there's something running synchronously behind the scenes in HttpClient or something (which I've heard tell is the case in at least some versions of .NET), it won't do anything because the synchronization context will schedule the continuation on the UI thread and might even give it a higher priority than processing inputs and window messages.
|
# ¿ Sep 14, 2020 21:47 |
|
adaz posted:an oldy but a goody on async await TPL best practices from Tech Ed 2014 David Fowler's writeup is also a nice introduction to this stuff.
|
# ¿ Oct 29, 2020 20:55 |
|
One of the objections I've heard even when the type is explicit on the right side of a declaration is that it can feel weird in some way for left-to-right readers. C# 9.0 adds target-typed new expressions, so pedants will have a new dimension of opinions to inflict on each other in a few days.code:
|
# ¿ Nov 10, 2020 02:11 |
|
please stop building distributed monoliths, i'm dying
|
# ¿ Jan 18, 2021 20:03 |
|
edit: maybe misinterpreted the problem what if you...threw an exception for an error No Pants fucked around with this message at 13:01 on Feb 28, 2021 |
# ¿ Feb 28, 2021 08:36 |
|
You usually only find out that they're incompatible during runtime when your poo poo breaks because a method is missing somewhere.
|
# ¿ Jun 3, 2021 23:33 |
|
It gives the number you wanted in your example at least, on .NET 5. You only need G9 to round-trip a float, so it seems to be formatting as much as it can. Maybe.
|
# ¿ Aug 28, 2021 20:10 |
|
The new extension methods are for fairly simple scenarios. They're just calling HttpResponseMessage.EnsureSuccessStatusCode(), which only gives you the status code, so you're on the right track. Mind, you can still use GetFromJsonAsync() and have retries based on response headers if you feel up to creating a custom retry policy using Polly. No Pants fucked around with this message at 04:48 on Jan 6, 2022 |
# ¿ Jan 6, 2022 04:34 |
|
Rocko Bonaparte posted:I had seen your response yesterday but I had to double check something today. I also have a similar with where I use a List<> and I thought Equals() was comparing contents there. But I checked it today and bam, I am manually comparing contents. So that is what I get for 2AM coding. if this is still for unit testing, testing frameworks usually have an equality assertion method that compares the contents of collections.
|
# ¿ Jan 22, 2022 21:20 |
|
If what's in System.Globalization isn't what you're after, you probably need to go directly to Normalizer2 from ICU. Here's an example using icu.net:C# code:
|
# ¿ Jan 28, 2022 08:32 |
|
I can see that being adequate if it's being passed around, especially if you aren't adding keys. The AsyncLocal<>.Value property's get/set methods retrieve and store the actual references to the values on the current ExecutionContext, so there shouldn't be a memory leak concern. (Maybe if you're doing something weird with the event handler delegate, as that's the only state stored by an AsyncLocal instance.)
|
# ¿ Jan 30, 2022 01:32 |
|
nielsm posted:Case folding is a particular algorithm/transformation specified by the Unicode standard, yes, and it isn't quite the same as an "uppercase" or "lowercase" function, which is by definition human language sensitive. Case folding is tracked by this issue, and there's some more discussion here. The gist is that the .NET team is reluctant to maintain globalization functionality themselves, and if they were going to expose APIs for case folding, they'd likely call into the ICU library provided by the OS, probably with some workarounds for older versions of Windows.
|
# ¿ Feb 3, 2022 20:22 |
|
fuf posted:man I still have such issues with EF and saving related entities. I just don't get it at all. Assuming this is EF Core, you're on the right track. You can re-attach the Filter object with DbContext.Update(): C# code:
No Pants fucked around with this message at 17:14 on Feb 5, 2022 |
# ¿ Feb 5, 2022 17:11 |
|
The compiler (pre- and post-.NET 6) will convert an interpolated string to a string literal or a string.Concat call if the parameters line up, so it isn't all bad. The main thing in .NET 6 is fewer heap allocations for the non-trivial cases (edit: and exposing some types that allow methods to consume interpolated strings and do stuff themselves).
No Pants fucked around with this message at 19:47 on Mar 3, 2022 |
# ¿ Mar 3, 2022 19:38 |
|
insta posted:I know the compiler converts simple, compile-time string concats into a string.Concat call -- but I'm seriously surprised it can't figure out how to do that for the Interpolated example in my code. Yeah, I was talking about $""-type string interpolation. The earlier behavior where $"" is a shortcut for string.Format was more desirable because using string.Concat would allocate an extra string for the formatted int.
|
# ¿ Mar 3, 2022 23:40 |
|
The C# 10 compiler can lower an interpolated string to using the DefaultInterpolatedStringHandler type, too. Like this C# code:
C# code:
|
# ¿ Mar 5, 2022 15:37 |
|
epswing posted:Am I missing something obvious here? The documentation for what you're trying to do is hidden here. After adding the Microsoft.Extensions.Logging.AzureAppServices package, these are the relevant parts in .NET 6: C# code:
|
# ¿ Sep 20, 2022 20:05 |
|
epswing posted:I'm having more fun with AspNetCore logging. Log levels for App Service file logging are controlled by a file that's apparently normally updated through the Azure Portal. Looking through the source code, it's a setting called "AzureBlobTraceLevel" in %HOME%/site/diagnostics/settings.json. The provider also doesn't do category-based filtering, so if you want that, you need to use a more robust logging provider.
|
# ¿ Mar 5, 2023 10:51 |
|
epswing posted:Ah you're right, the settings.json file is controlled by the Azure "App Service logs" UI page Where I work, I've mostly seen services exporting to Application Insights/Log Analytics or an internal OpenTelemetry thing, which only requires configuring logging providers like you were doing.
|
# ¿ Mar 6, 2023 03:06 |
|
NihilCredo posted:
I might be missing something, but that code block will throw a NullReferenceException if thing is null. A property pattern only matches an expression if the expression result is not null.
|
# ¿ Jun 14, 2023 13:34 |
|
Red Mike posted:Property patterns won't throw if it's null, it'll just early quit and act as if it's not a match. Yeah, that's what I posted. It'll throw an exception when it gets to DoSomething(thing.SomeProperty);
|
# ¿ Jun 14, 2023 20:06 |
|
|
# ¿ May 17, 2024 18:32 |
|
Munkeymon posted:I'm trying to hook up Azure App Services running a Framework ASP monolith up to an App Configuration service and I've almost got it working with just web.config changes, but I can't figure out how to load the connectionString (or endpoint for that matter) from the environment/App Service's Configuration. Is there some "magic" way to tell the config parser to grab a string from the environment's connection strings or... something? Configuration builders section of the config for reference: You've probably already figured it out, but there's a quickstart that shows how to grab the connection string from configuration. Adding AzureKeyVaultConfigBuilder to the mix is probably not too difficult.
|
# ¿ Mar 28, 2024 18:06 |