simpleIoc | 自己实现一个简单的IOC,非常的简单,当然也少不了依赖注入
kandi X-RAY | simpleIoc Summary
kandi X-RAY | simpleIoc Summary
simpleIoc
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Read bean definitions from XML
- Parse the properties of an element
- Process a BeanDefinition element
- Parse bean definitions
- Create bean
- Gets the bean
- Get bean
- Add property value
- Register a bean definition
- Set bean
simpleIoc Key Features
simpleIoc Examples and Code Snippets
Community Discussions
Trending Discussions on simpleIoc
QUESTION
I'm trying to pass some data values from my shared project for access via an iOS AppDelegate.cs method. I don't want to go into too much detail here, as I don't want to limit the reach of this question. But the Method could be called at any point and is used to gain state information about the app, e.g. isLoggedIn etc.
We're using GalaSoft.MvvmLight.Ioc.SimpleIoc
and have a CustomViewModelbase, but that probably not too relevant.
The values are mostly part of our CustomViewModelbase
, I thought I could create some kind of global object on App.Xaml.cs, which would be accessibily in AppDelegate.cs
Here's what I have...
...ANSWER
Answered 2021-Apr-23 at 10:46Create a global variable in App.cs , initialize it in constructor.
Return the value from a public method and access it in iOS project .
Forms App.csQUESTION
I am using MVVM Light to write a WPF App, my initial idea is to use Static Httpclient for abstracting data from multiple devices, there is a issue regarding the DNS with Static Httpclient. So, If I am going to use IHttpClientFactory, How should i go about setting up?
What I read is My MainViewModel Constructor will need to do this:
...ANSWER
Answered 2021-Feb-03 at 20:45You could use the HostBuilder
in Microsoft.Extensions.Hosting to create a DI container in the ViewModelLocator
:
QUESTION
I created a class AppConfig :
...ANSWER
Answered 2020-Dec-20 at 14:08Create in interface that abstracts the desired class.
QUESTION
I have been reading about MVVM (and MVVM Light) lately, so tried to implement in an application with 2 ViewModels.
When I use the ViewModelLocator in the datacontext the Command binding does not work, if I bind the ViewModel to the datacontext of the ViewModel itself it works!
What am I missing here?
...ANSWER
Answered 2020-Oct-16 at 09:53The user control's data context is a ViewModelLocator
and the button is binding to MoCoConnectCommand
property. But the class ViewModelLocator
don't have the property MoCoConnectCommand
.
I think you need inject MotionViewModel
in the user control's data context, like :
QUESTION
What I'm doing:
On my DataGrid I have a context menu to add Template items. The MenuItems are created dynamically using the ItemsSource property of the parent MenuItem. The ItemsSource is an ObservableCollection of my template objects. I want to get the Header of the dynamic MenuItems from the collection object properties, but execute a command from my main ViewModel. The main ViewModel is bound to the DataContext of the root Grid.
My issue:
The MenuItems are created properly and I can also bind the header to a property of an object in the collection. But the Command binding does not work. I can see an error in the output window: "System.Windows.Data Error: 4 : Cannot find source for binding with reference..."
Here is my code reduced to the issue (using MVVM light):
MainWindow.xaml:
...ANSWER
Answered 2020-Feb-26 at 08:05You can access the ViewModelLocator
inside the ItemTemplate
as well.
QUESTION
I'm confused about the patterns: ViewModelLocator
, ServiceLocator
, Dependency Injection
.
The latest conclusion are as follows:
ViewModelLocator
. The place to connect View
and ViewModel
.
ANSWER
Answered 2020-Feb-21 at 09:39You recently asked a related question, and from it I infer that ViewModelLocator
etc. originate from the sample code base you linked to there. From what I gather from the code examples shown so far, it doesn't look like that code base is the best example of using Dependency Injection.
Thus, any question that involves explaining the 'patterns' in that code base should be met by the response mu.
The question implies a false premise. The premise is that there's something to be learned from that code base. That may not be the case.
Service Locator isn't a pattern; it's an anti-pattern. (Most people seem to agree with me, and so far no-one has been able to produce a compelling counter-argument.)
Dependency Injection isn't a pattern; it's a set of design principles and (several) patterns. That's what we've attempted to describe in our book.
how then to connected
View
andViewModel
?
The best explanation of the MVVM pattern is still, I believe, Josh Smith's original article. If you want to see a complete code example that combines MVVM and Dependency Injection, it's available with the first edition of Dependency Injection in .NET (which is also included as a free e-book with the new edition).
ServiceLocator
only needs to store Services?
No, there should be no Service Locator at all. That's an example of what I mean. It seems that that code base isn't a good way to learn about Dependency Injection. It generates more confusion than insight.
QUESTION
The problem is moving from the ServiceLocator
anti-pattern to Dependency Injection
. In view of my inexperience, I can't shift the DI principle to the code implemented now.
The Summary section is optional for read. You may want to comment on something, advise.
The main purpose of the program is the process of merging placeholder fields of specific information. Number of information makes need to have infrastructure around. Such as forms, services, database. I have some experience with this task. I managed to create a similar program based on WinForms
. And it even works! But in terms of patterns, maintenance, extensibility, and performance, the code is terrible. It is important to understand that programming is a hobby. It is not the main education or job.
The experience of implementing the described task on WinForms
is terrible. I started studying patterns and new platform. The starting point is UWP
and MVVM
. It should be noted that the binding mechanism is amazing.
The first problem on the way was solved independently. It is related to navigation in the UWP
via the NavigationView
located in the ShellPage
connected with ShellViewModel
. Along with creating a NavigationService
. It is based on templates from Windows Template Studio
.
Since there is a working WinForms
program and its anti-pattern orientation, there is time and a desire to do everything correctly.
Now I'm facing an architecture problem. Called ServiceLocator
(or ViewModelLocator
). I find it in examples from Microsoft
, including templates from Windows Template Studio
. And in doing so, I fall back into the anti-pattern trap. As stated above, I don't want this again.
And the first thing that comes as a solution is dependency injection
. In view of my inexperience, I can't shift the DI principle to the code implemented now.
The start point of app UWP
is app.xaml.cs
. The whole point is to transfer control to ActivationService
. Its task is adding Frame
to Window.Current.Content
and navigated to default page - MainPage
. Microsoft documentation.
The ViewModelLocator
is a singleton. The first call to its property will call constructor.
ANSWER
Answered 2020-Feb-20 at 21:59As @Maess notes, the biggest challenge you face (right now) is refactoring the static dependencies into constructor injection. For example, your ShellViewModel should have a constructor like:
QUESTION
I using MVVM light library in my project. I trying to add an array to the constructor of the ViewModel.
For example... if the code below is
...ANSWER
Answered 2020-Feb-17 at 15:10You could register a Func
in the ViewModelLocator
where you initialize the array:
QUESTION
We've got a WPF app with a landing page that lists about a dozen or so buttons, all going to new views/viewmodels of that type. Its becoming unwieldy. We've got one viewmodel that lists all of these which basically look like this:
...ANSWER
Answered 2020-Jan-29 at 23:34This is going to be psuedo codish advice which is kind of on the same track where you already are:
Assuming BaseViewModel is the base class for all your individual VM's
- Create a Dictionary
Fill this dictionary up during Application Start time (would look like your tiles List)
public void PreCreateVMs() { dictionary[Key] = new ConcreteViewModelType(); // Keep adding New Vms here }
In the xaml, bind all your buttons to same Command which takes a string argument (or improvise this with Enum). Pass the correct String Key for each button. Like: Accounts Button click should launch AccountVM which is stored with "AccountVM" key in the dictionary.
- In the Command Handler - use the string, lookup the Dictionary find the correct ViewModel and Assign this object to CurrentViewModel
From maintenance point of view - all you need to add a new ViewModel is to update xaml with a new button, assign correct command parameter string. Use this string key and add the correct VM in the PreCreateVMs method.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install simpleIoc
You can use simpleIoc like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the simpleIoc component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page