Tom
avalonia vs react native and other "electrons"
I've been experimenting with Avalonia UI for few months for my hobby project. I don't have any previous experience with WPF, UWP or anything based on XAML but did some html frontend.
I know there are some "frameworks" to make a web app standalone desktop one, e.g. react native, electron, etc.
Do any of you have any insights how those compares to Avalonia in terms of final outcome "robustness"?
2 replies
✅ Disposing dbContext with dependency injection
Hi!
I am developing an Avalonia UI app. I am displaying there some data, which is stored in the sqlite database. The data - rows in that matter - can be deleted or added, but once they are there - they are not modified (at least for now ;)).
I have a factory which gets data from db and then creates a view model passing there the data (and few other things). The factory itself I've registered in service container as a singleton and dbContext as a transient. dbContext is injected into the factory. As I am not tracking entities changes and not adding or deleting data in that place, I've configured the context with
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
.
I have not encountered any issues so far, however I am concerned about proper dbContext disposing. If a factory is singleton, even when dbContext is transient, once it's injected is still there, right? The view model can be created few times during app lifetime, rows can be added/removed in the meantime.
Can I leave it as it is or should I do smth about it? Eg. instead of injecting dbContext itself I can create and inject another factory which will instantiate dbContext via constructor each time needed, or maybe you can suggest other solutions?
Any help appreciated 😉28 replies
Global key events listener (when app window is minimalised or out of focus)
Hi! I'm making an Avalonia UI app and I want to listen to keyboard events even when app window is minimalised or I'm doing smth else in other app. Do you know a "good" way to do that? As far as I know it's not possible to do it through Avalonia itself and additional library is needed. I looked on NuGet, but those I found were not really pupular.
4 replies
✅ Methods (with bodies) in interfaces
Hi!
C# allows interfaces to contain methods already with some implementation (i.e. with body).
As I can easily think about taking advantage of this, but doesn't it deny the main reason interfaces exists - i.e. to abstract things?
If it were your decision whould you use this functionality in your project or stick only to other options (like putting logic inside abstract classes, using services, etc.)?
13 replies
✅ Predicates
Have you ever "add" more than one function to predicate definition:
e.g.
Predicate<T> p = func1;
and then p += func2;
If so in what circumstances?
From my limited experience it does not make much sense, however compiler has nothing against that 😉 Maybe just because Predicate is based on delegate...8 replies
✅ Design of events
Hi!
I have a question about utilization of events. Don't know many real life production examples by myself, but counting on your experience 😉
I've noticed that EventHandler delegate takes two parameters: object sender and EventArgs or other defined type. That means that in subscribers we can't be sure what is the sender and what are its properties/methods. So what's the main purpose (by design) of this "sender" parameter, shall it be used to check what type it is and take actions based on that? I am aware that I can create my own type of event instead of using EventHandler, but anyway I'm curious about the real life usage of the sender object.
35 replies