[Unity] Dependency Injection?
Hey,
I could not find anything on the forum regarding IoC/DI. Is there a way to use DI in NoesisGUI or are there plans for the future?
I could not find anything on the forum regarding IoC/DI. Is there a way to use DI in NoesisGUI or are there plans for the future?
Re: [Unity] Dependency Injection?
Could you elaborate about it? How do you think Dependency Injection could be included in NoesisGUI?
Re: [Unity] Dependency Injection?
I asked just out of curiosity since this gets often mentioned in MVVM and WPF articles. I vaguely remember using DI a long time ago working on a WPF project so I wondered if noesisGUI has an IoC of some sort.
I think this can explain it better than me:
http://wpftutorial.net/ReferenceArchitecture.html
I think this can explain it better than me:
http://wpftutorial.net/ReferenceArchitecture.html
Re: [Unity] Dependency Injection?
At first, I would say that it can be done on top of NoesisGUI without having to change anything... But I would like to hear the opinion of somebody that has already experience with this pattern.
Re: [Unity] Dependency Injection?
Well, DI has not that much to do with Noesis in general, it's just a pattern to inject dependencies. So the first step would be to decide what DI framework you want to use. There is for instance StrangeIoC which was primarily written to be used within Unity.
The next step would be to declare all types that should be known and also be injected. You also have to decide what type of injection you want.
The problem with DI is that it won't work when you just call the constructor of a class, such as "new ViewModel()". Instead, depending on the DI framework, there are other ways to create object instances. In the linked WPF article they use a unity container and call Resolve() or TryResolve() to create a new instance of a class. This will also inject the 'marked' dependencies.
That's where you might stumble when you use Noesis and just declare views or viewmodels within XAML, as you have no control over the construction process. Also the 'ViewModels' are relatively closely bound to the 'View' in Noesis.
Hmm, now that I think about it there might be a way to achieve a better separation. I have to check whether I can convince Noesis to work that way. On the other hand I'm happy that I finally got it finally working more or less the way I wanted. There might also be a problem with "OnPostInit()" as there are certain things that shouldn't be put in the constructor.
Anyway, I solved it by just creating all views in code instead. But the goal of my GUI is to be pretty flexible. For a more simple UI that might not be the best approach.
The next step would be to declare all types that should be known and also be injected. You also have to decide what type of injection you want.
The problem with DI is that it won't work when you just call the constructor of a class, such as "new ViewModel()". Instead, depending on the DI framework, there are other ways to create object instances. In the linked WPF article they use a unity container and call Resolve() or TryResolve() to create a new instance of a class. This will also inject the 'marked' dependencies.
That's where you might stumble when you use Noesis and just declare views or viewmodels within XAML, as you have no control over the construction process. Also the 'ViewModels' are relatively closely bound to the 'View' in Noesis.
Hmm, now that I think about it there might be a way to achieve a better separation. I have to check whether I can convince Noesis to work that way. On the other hand I'm happy that I finally got it finally working more or less the way I wanted. There might also be a problem with "OnPostInit()" as there are certain things that shouldn't be put in the constructor.
Anyway, I solved it by just creating all views in code instead. But the goal of my GUI is to be pretty flexible. For a more simple UI that might not be the best approach.
Re: [Unity] Dependency Injection?
Great answer, @Scherub!
I work mostly on GUI heavy apps and somethimes one ViewModel depends on another ViewModel or service. Can you perhaps elaborate on your workflow a little bit?
I work mostly on GUI heavy apps and somethimes one ViewModel depends on another ViewModel or service. Can you perhaps elaborate on your workflow a little bit?
Re: [Unity] Dependency Injection?
About the "convince Noesis". Yes, we are open to suggestions, improvements... As soon as v1.2 is released I think we will be able to dedicate the energy to new things.That's where you might stumble when you use Noesis and just declare views or viewmodels within XAML, as you have no control over the construction process. Also the 'ViewModels' are relatively closely bound to the 'View' in Noesis.
Hmm, now that I think about it there might be a way to achieve a better separation. I have to check whether I can convince Noesis to work that way. On the other hand I'm happy that I finally got it finally working more or less the way I wanted. There might also be a problem with "OnPostInit()" as there are certain things that shouldn't be put in the constructor.

By the way, I am really curious about what you are developing using noesisGUI.
Re: [Unity] Dependency Injection?
@zyzyx: Can you be a bit more precise, please? Otherwise I don't know where to start. 
@jsantos: It's a bit early to show anything. Not only is everything coders art and all of the graphics are place holders, there are also a lot of missing gui elements that I would like to integrate/implement first.

@jsantos: It's a bit early to show anything. Not only is everything coders art and all of the graphics are place holders, there are also a lot of missing gui elements that I would like to integrate/implement first.

Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 4 guests