« first day (2350 days earlier)      last day (1799 days later) » 

10:47 AM
Hi all
 
 
1 hour later…
12:12 PM
Hi good guys
 
Morning
 
@ButterJones I don't have any idea what's the problem
if you remove container.Verify(); will it work?
(I know it is not recommended just want to understand what's going on)
 
I have a trivial question on general C# programming, but I can't find an answer on my own...
I have a class defining an event and a delegate:
public delegate void MyDelegate();
public event MyDelegate MyEvent;
Now I want to define an Interface that forces its implementer to match those event and delegate.
I can define
event MyEvent;
but I don't understand how to define the delegate signature...
 
12:32 PM
I see... delegate is defined once for all along with the interface, and the interface implementers are taking the common delegate definition...
 
as per MS source code you don't even need it as a property:

https://referencesource.microsoft.com/#System/compmod/system/componentmodel/INotifyPropertyChanged.cs,fd4b42d7e29d53e5
(using INotifyPropertyChanged as a point of reference)
 
I was trying to "force" the event handler signature in the interface
 
it's already done that way isn't it?
(in the MS implementation) ?
its saying that PropertyChanged has to be of type public delegate void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e);
which is what you're trying to force (semantically)?
so this should work:

public interface MyInterface{
    event MyDelagate MyEvent;
}
 
sorry Maverik I think I'm not clear enough. The info from Alex and you answered my question, i.e. delegates are not defined inside the interface, but somewhere else, publicly available to event subscribers.
 
ah yea no
 
12:38 PM
I was not having success because I was trying to define the delegate inside the interface
 
aaa
 
hey guys, do you know if its possible to keep an object alive between calls in asp.net web api?
I was looking for the equivalent location like app.cs in WPF but there is none
and my object initialization is time consuming, so I just want to initialize it only once
 
Ah, the challenge of a stateless protocol
 
kind of silly they don't consider that
 
erot, I don't recommend this, but... stackoverflow.com/questions/11478244/…
 
why do all these answers keep hammering the 'stateless' definition
i totally disagree that keeping an object alive violates the statelessness of web api
 
1:24 PM
an API that follows REST doesn't keep any objects alive between requests
well, i suppose that isnt strictly true
i am sure there are good cases to keep infrastructure based things alive
but i would think anything client request related is created on a per request basis
 
1:54 PM
Good morning!
 
Hi Lynn
 
hiya Alex
man, I still need to reserve some time to take a look at the thing you sent a while ago
 
2:30 PM
No worries!
 
what if your rest api need to analyze data from users and spit back results - and say its doing that by machine learning and needs to load some huge model in order to do its analysis?
you can't expect it to load the model every single time a request comes in - that would be crazy slow and inefficient
 
you are free to make APIs that suit your needs that don't follow REST
tbh i dont really know where the line is drawn
its probably like MVVM where adhering to it too strictly is just a handicap
 
I still consider my above scenario restful though
 
2:45 PM
REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully. A REST API should not rely on data being stored on the server or sessions to determine what to do with a call, but rather solely rely on the data that is provided in that call itself.
Identifying information is not being stored on the server when making calls. Instead, each call has the necessary data in itself, such as the API key, access token, user ID, etc. This also helps increase the API’s reliability by having all of the data necessary to make the call, instead of relying on a series of calls with server state to create an object, which may result in partial fails.
 Instead, in order to reduce memory requirements and keep your application as scalable as possible, a RESTful API requires that any state is stored on the client—not on the server.
 
Morning/Afternoon everyone!
 
Hi biggi
 
I am away from desktop programming for a while
what is current way of building windows native, windows store apps in common now?
Windows universal apps type of thing?
 
Windows Store? I think store apps have to all be Universal Windows
I don't use the store, so I still primarily work in WPF for standalone apps.
 
ok, and xamarin can do it to even cover mobiles?
or we need to make separate apps for those
 
2:58 PM
^ that was designed to allow you to publish desktop applications on the windows store
 
if it is something similar to porting .NET to .NETCore. No. Thanks :)
 
I don't believe there's any porting involved.
(full disclosure: I haven't used it.)
 
I see, thanks for the link. I was more asking "building from scratch" approach, and where to start.
 
Oh... start with UWP if you want to publish on the Store.
 
What happened to WPF apps now, it is Windows Native only? And non store apps? (not counting this bridge option)
 
3:01 PM
(As Zarenor mentioned)
Well, they now have WPF support in .net core 3
But only under Windows.
(DirectX)
 
That's right. WPF still hasn't been made cross-platform - Xamarin is cross-platform. UWP is windows-only, but includes tablets and windows phones (which are no longer sold)
 
Xamarin has support UWP so you can publish app in the store
 
@FoggyFinder I removed the container.Verify() and it did not work.
@Maverik Do you know how I can force the thread back onto the UI thread that I need?
 
3:16 PM
@ButterJones In WPF? There are a couple of ways. Are you doing this in async? If you haven't used .ConfigureAwait(false), then you'll be in the correct 'Context'. If you're not using async, it's less automatic.
 
@Zerenor I'm having an issue caused by SimpleInjector that @Maverik believes is caused by SimpleInjector where my UI thread moves to another one.
Here is the link to my question. https://stackoverflow.com/questions/55343827/why-c-sharp-wpf-button-binding-command-wont-change-view-after-using-simple-inje/55348322#55348322
To answer your question directly, I'm actually not sure if I'm doing this in async and I haven't used the .ConfigureAwait(false) in my code.
 
@ButterJones Google for SynchronizationContext
 
@LynnCrumbling So at the beginning of my program, I can capture the SynchronizationContext and then switch back when I need to Navigate between views?
 
Exactly.
 
Typically, I capture the Dispatcher when I need to, using Dispatcher.CurrentDispatcher in the constructor.
Then I can always invoke back to that. If you build up a proper async workflow, you can even do those invocations asynchronously.
 
3:26 PM
So I take it I want to capture this before I inject dependencies in my App.xaml.cs (startup file) and then pass that context to my ViewModel. Then when the button gets clicked, I just switch back over to the context and then run the code to switch the view?
 
It's seen that approached used as well:
33
A: How to pass the UI Dispatcher to the ViewModel

Vitaliy Markitanovwhy would not you use System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => {ObservableCollectionMemeberOfVM.Add("xx"); } )); instead of keeping reference to GUI dispatcher.

 
You can capture it at any point when you know you're in the correct context.
Oh, that answer is good. I forget you can do that'
 
(I've needed both approaches, for different reasons)
 
If you don't want to keep the reference around (or might not have a good way to inject it)
 
Also for some background, my button bindings still work and when I click the button, the command binding function that I write gets called.
Is this context/dispatcher method still relevant (just checking to rule out some things).
 
3:28 PM
Under the hood, SyncContext magically figures out how to work it -- it works with WinForms, which does not have a dispatchers
SyncContext knows which framework it is running on, and branches.
For a good read on this, check out: It's All about the SynchronizationContext MSDN Article
 
^^^
 
Good discussion there about framework-specific under-the-hood impl of SyncContext
 
And how and why the differences.
 
So this line of code: System.Windows.Application.Current.Dispatcher.Invoke(
(Action)(() => {ObservableCollectionMemeberOfVM.Add("xx"); } ));

How exactly do I use this?
 
So, when you're in a System.Windows.Application, the .Current refers to the class defining it (your App class), and that retrieves the dispatcher for it, which dispatches to the GUI thread.
 
3:34 PM
System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { /* code here runs on UI thread */ } ));
 
You need to put, I think, your code inside your functions, in an invoke call. There are two ways you might do this.
You might:
private void OnGo2Screen(object obj)
        {
            System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => {
            ChangeViewModel(PageViewModels[1]);
            });
        }
Or, you might:
        Mediator.Subscribe("GoTo2Screen",System.Windows.Application.Current.Dispatcher.Invoke( o => OnGo2Screen(o));
I may have mismatched delimiters or parens in those, so check them
 
Zarenor -- as more context (ha, pun), I needed to use SyncContext because the code in question was in a library that was consumed by both a WPF application and a Winform application
 
@Zarenor I tried your first solution (I fixed params) and that didn't work.
I tried your second solution verbatim, and I'm not sure what the **o** in o => OnGo2Screen(o) is, so I did the following:
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
Mediator.Subscribe("GoTo2Screen", OnGo2Screen);

}));

And I got a NullReferenceException on program startup.
 
Right. I... don't know what the thing you wrote would do. It's key that the dispatcher invocation is part of the delegate being called
The 'o' is the object argument to OnGo2Screen
Since there's an argument, you have to name it. It avoids any ambiguity errors there, I think.
The Mediator.Subscribe line I wrote was intended as a drop-in replacement at the location you were already doing that - the MainWindowViewModel ctor, I think
 
3:50 PM
Yeah, I put it in MainWindowViewModel.cs.
When I do the line Mediator.Subscribe("GoTo2Screen", System.Windows.Application.Current.Dispatcher.Invoke(o => OnGo2Screen(o)));, I get an error that says "Delegate Action does not take 1 arguments.
 
That's.... Odd. OnGo2Screen has a single argument because, it seemed to me, Mediator.Subscribe takes the arguments string name and Action<object> callback. Am I mistaken?
 
Mediator.Subscribe is defined as:
public static void Subscribe(string token, Action<object> callback)
So you are correct.
 
Yeah. I see my error
Just found it
One sec.
First, lets define var dispatcher = System.Windows.Application.Current.Dispatcher.
So I don't have to write all that every time.
 
Then, you want: Mediator.Subscribe("GoTo2Screen", o =>System.Windows.Application.Current.Dispatcher.Invoke(() => OnGo2Screen(o)));
And then I copypasta'd anyway and it didn't matter. I don't know why I do things, sometimes.
Had to make it a closure a different way. The nested closure is a little nasty, but it's only one level of nesting, so the cost shouldn't be too high.
Do you understand what the difference there is?
(If not, I'd like to explain it, so it's clear)
 
3:57 PM
Yeah I can see the difference.
Unfortunately, it did not make the buttons work.
 
Hm. Okay. Let me reread your question and see if I have another idea.
 
I think I need to get the current dispatcher before I inject because I think SimpleInjector is causing the threads to desync.
 
I.. I'm wondering if there's another issue. I have to go to lunch (meeting someone), but I'll see if I have another idea when I get back. Can you make one change for me?
 
Sure, no problem.
 
Can you initialize _goto2 in the constructor, and make it a readonly field? I'm wondering if something strange is happening there in the SimulationCaseViewModel
I'll be back after lunch.
 
4:02 PM
Ok I'll make those changes. Thanks
 
4:16 PM
@Zarenor I did what you said, but that didn't fix my button. I confirmed that the new functionality 'should' work because I also made those same changes in a similar project that doesn't use SimpleInjector and my page navigation worked just fine.
 
 
1 hour later…
5:23 PM
Hm. Reading through this, I am at a bit of a loss. I'm not quite sure why it would behave this way. It seems like it's set up reasonably. I'm not sure what the behavior of the mediator is, but I assume you've checked that the calls in the MainWindowViewModel are being made - that it gets as far as calling OnGo2Screen.
It's possible to use the threads window to see if we can confirm whether or not it's on the correct thread when that happens.
But otherwise, I'm definitely at a loss.
 
6:23 PM
I came across an xUnit test project on NuGet.
It made me wonder, does MS use their own test framework internally?
Matter of dog food.
 
@Zarenor Yeah, it calls OnGo2Screen and hits the CanExecute function, and doesn't get any further than that.
I think I'm going to just not use SimpleInjector and handle DI myself (sigh).
 
I... don't understand. If it calls OnGo2Screen - that's the Execute function. CanExecute is pretty irrelevant if the Execute function is being called.
... Is there a particular reason you have the ChangeViewModel method set up the way it is? (Just looking there because that's the next link in the chain)
The 'cache the new VM if I don't have it', and then 'equality test for the same one in the list' seems.... strange
If you have a reason for doing it that way, great. But since you're both 1) loading these in the ctor and 2) using the list to reference them when calling ChangeViewModel, it seems... redundant?
I'm just trying to think through anywhere where this could be an issue. I do want to be clear: The invoke calls we gave you do force it into the UI context. There's... not really a way for that to go 'wrong'. That would be a problem for the entire UI system, not just for changing the VM and view displayed.
 
i've had it go wrong when you end up in tasks that have been dispatched with dispatchers inside
 
Threads aren't these mysterious chaos behemoths. You can cause really strange and odd behavior with them, if you're changing data from multiple threads at once, for example. But Microsoft knows how that happens, and has ensured it doesn't - that's why you get exceptions when you try to change things that the UI is watching. With the changes we've tried, I really do not think this is a threading issue. Or I think if it is, we've fixed that portion of it.
 
No, I don't have a reason for setting up my ChangeViewModel method like that. How can I break it up?
 
6:37 PM
'Nothing happens' is not the failure mode for that kind of error, is what I mean.
I would just do:
private void ChangeViewModel(IPageViewModel viewModel)
        {
            if (!PageViewModels.Contains(viewModel))
                PageViewModels.Add(viewModel);

            CurrentPageViewModel = viewModel;
        }
Also note that .Contains() will use the .Equals() call on the object - if you haven't defined an override, it's equivalent to a reference check. Here, I think that's okay, but it can be a footgun sometimes. I've had errors when I expected some other behavior.
Since you're using that to enforce that the visible ViewModel is available in PageViewModels, I would also make the CurrentPageViewModel setter private, to ensure that's enforced.
Alternately, you could merge this code and the setter. Then it's a little more 'expensive' than you might expect a setter to be, but it enforces the contract you want enforced, and does so transparently
Does all that make sense?
 
When I set CurrentPageViewModel setter to private, I got the following error: System.ArgumentNullException: 'Value cannot be null.
Parameter name: MainWindowViewModel does not contain property: CurrentPageViewModel'
 
7:04 PM
Uhh. Hm. I wonder what's trying to set it
Maybe that's the issue? Maybe SimpleInjector is doing something odd with that?
I don't know SimpleInjector at all, for what it's worth. I don't know how much of this it does or doesn't do automatically
 
I just rewrote my code to not use SimpleInjector and I injected all my dependencies just fine and navigation buttons still work.
I think I'm just gonna go with this solution and move forward.
Thanks for all the help.
 
Sure. Sorry we couldn't work out the issue with SimpleInjector.
 
7:37 PM
so to give context to rest of you with my Thread comment..
The bit of info I picked up on was that change event was getting lost for UI when going via DI.. and that's what made me think event maybe getting raised on wrong thread
but its not a concrete diagnosis.. just a quick idea at 1am
you guys have clearly gone far more in depth at this point so I'll stay quiet :)
 
No, I think it's a reasonable guess. It probably would have been the first thing I reached for, too.
 
7:55 PM
that Q seems like a good choice for bounty
 
mm butters can't offer it unfortunately
just discovered this as an alternative way of RPC over web:
 
I know he can't. I'll do it if no more ideas appears
 
seems to support javascript+.net among other things so could be an alternate to push based UI
I'm not sure i'd do a bounty on that considering his problem seems to revolve around SimpleInjector
also main site for RSocket is rsocket.io
this would be very handy for guys who are already comfortable with Rx as .net client heavily relies on IObservables
this seems like a good image to show it off:
RSocket based resources: github.com/linux-china/awesome-rsocket
gotta jet but i'll see if i can play around with it and get something trivial going.. might need help on JS side of things.. not sure how to get it to display a streaming counter for example
be back in 2 hours
 
8:13 PM
This morning I tried to simplify code from the Q but seems like I went a bit far than needed. I removed SimulationCaseViewModel and IStreamRepository so there were only "original" VMs / UserControls. Code doesn't work indeed. When I removed container.Verify(); just in case app started to work. I didn't look into the source of Simple Injector and to be honest - I don't want to do it. At least yet
Ok, started a bounty
 
0
Q: Why C# WPF button binding command won't change view after using simple injector?

ButterJonesI'm using the following articles for starter code: Navigating Between Views in WPF MVVM Simple Injector WPF Integration Objective: Trying to go from View 1 to View 2 in WPF form using a button binding command and Simple Injector to inject dependencies into views. Note: These dependencies are rep...

 
9:04 PM
0
Q: Changing UserControl based on property in ViewModel

pfinfernoI want to change the view inside of a ContentControl based on an enum property in the ViewModel for the Window hosting these controls. Below are two sample UserControls: <UserControl x:Class="View1"> <Grid> <Button /> </Grid> </UserControl> <UserControl x:Class="View2"> <Grid>...

 
 
1 hour later…
10:05 PM
@FoggyFinder wow, 200...
 
> Passing the DI container is service location and is an antipattern.
> It's important to note that accessing instances of objects via the ObjectFactory [a DI container] within your View Models is considered an anti-pattern. (Source)
I see DI containers as a way [one of several ways] to inject cross-cutting facilities. (For example, it's convenient to be able to inject loggers and configuration objects through DI container.)
ViewModels often have satellite [or helper] objects. ICommand objects are an example. These satellite objects often need to make use of cross-cutting facilities. It would be nice to inject the cross-cutting facilities using the DI container. It makes every bit of sense to register these satellite objects with the DI container.
If I follow the rule which says that I shouldn't pass the DI container to the ViewModel, then I have to inject every ICommand object as constructor parameters. There can be lots of of satellite objects (dozens of different ICommand objects, for example), so there would need to be lots of constructor parameters.
That's what I'm having a hard time with.
ViewModels play powerful role in the application [and occasionally they overgrow into god objects]. I think that they may be trusted with a reference to the DI container.
At the same time, I agree that DI container should be invoked sparingly.
What if I relax the rule a bit:
"Passing the DI container to a ViewModel is not an anti-pattern. The DI container should be invoked only in the ViewModel's ctor. Invoking the DI container outside of the ViewModel's ctor is an anti-pattern."
 
10:52 PM
@FoggyFinder dang that's a generous bounty.. i hope there's some response at least
@NickAlexeev doesn't have to be only via constructor - you could have DI auto-inject property values too and then there wouldn't be that many ctor paramaters
of course that does depend on your container being able to do it
 
11:21 PM
@Maverik Microsoft.Extensions.DependencyInjection is my the DI container at this time.
 
that one does have property injection
 
Come to think if it, the ICommand objects are exposed through getter-only properties. If I want to inject the ICommand objects through properties, then these properties would have to have public setters.
@Maverik Overall, though, it looks like you are endorsing the rule that "passing a DI container to ViewModels is an anti-pattern". Are you?
 
i dont normally care too much about that if i need the thing for practical reasons
but in this particular case, yea there really doesn't seem to be a real need
also.. I'm not sure, but container may be able to still inject values in readonly getters via reflection.. experiment
 
@Maverik I'll give property injection a try. I've never played with that.
 
I just know that that's how IConfiguration used to be accessible in Startup class of asp.net core.. way back in start
 
11:29 PM
If that's indeed the case, it's a useful feature of IConfiguration.
 
not a feature of IConfiguration.. of MS DI :)
IConfiguration was the interface it used to inject
(so we could access config file values from Startup class)
 
@Maverik I feel that there is a need. So far, I'm having a hard time with creating a deep object graph without passing a DI container to lower levels. I should play with this more (one way and another). Maybe the fog will clear.
 

« first day (2350 days earlier)      last day (1799 days later) »