|
Can you point me to some articles on these DI specifically.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Honestly, when I was trying to figure out DI, I was never able to find any good articles, thats why it was so hard to wrap my head around. All the samples were very complicated . The way you write the code depends on what DI container you use (there are about 10+ open source ones -- I use my own light weight one).
Basically, using the ServiceLocator pattern, you'd write code like:
class MyClass : ViewModelBase
{
private IDialogService _dlgService = null;
public MyClass()
{
_dlgService = ViewModelBase.ServiceLocator.GetService<IDialogService>();
}
}
DI (Dependency Injection) does it automatically for you:
class MyClass : ViewModelBase
{
private IDialogService _dlgService = null;
public MyClass(IDialogService dlgService)
{
_dlgService = dlgService;
}
}
The benefit of DI is that depending on your MVVM framework, everything is automatic. In my MVVM framework, I have the DI integrated with the ViewLocatorService, so when the view is created, it uses the ViewLocator to automatically create the ViewModel. It automatically passes in all the dependent objects into your VM constructor.
Basically instead of new'ing up MyClass, you do something like:
MyClass m = ViewModelBase.DIContainer.Resolve<myclass>();
doesn't seem like much of a benefit when you are only taking in one service , but in a complex system, you could be taking in 10 services, and they could have dependencies of there own, etc.
Basically, DI handles passing in any registered objects into constructors and creating all necessary objects for you.
It also makes it easy to see what services a class is dependent on by looking at the constructor. A lot of the DI engines also allow you to not use the constructor method, but inject properties.
Like I said, I use my own light weight DI engine, but I think the most popular "main stream" ones are Unity and AutoFaq.
|
|
|
|
|
I'm sorry, but this is not the forum for airing grievances with votes. You have a perfectly adequate forum at the end of the posting for that.
|
|
|
|
|
I agree. I was pointing in that direction, but someone didn't follow.
|
|
|
|
|
error SocketError.AccessDenied on silverlight
|
|
|
|
|
Read this suggestion[^] then reformulate your question ONCE and someone may attempt to help.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
You need to open up a port (4502-4534) for socket communication in Silverlight.
This needs to be specified in the crossdomain or clientaccess policy file.
Read more here[^].
|
|
|
|
|
error SocketError.AccessDenied on silverlight
|
|
|
|
|
|
In a Silverlight app, assume you have UI, Data, Business, and WCF projects.
Does the UI talk to the service, which then talks to the BL, which then in turn talks to the DL?
Or does the UI talke to the BL, which then talkes to the service, which talks to the data??
Everything makes sense in someone's mind
|
|
|
|
|
In our structure we have 3 solutions:
Models holding the representation of the database objects.
WCF has the DAL and references the Models.
UI has the views and VMs and also references the Models and a service reference.
Within each solution there are additional projects depending on the solution required.
Most of the business logic is in the VM with some done in the WCF solution. As most of the business logic is driven by UI interaction we do it in the VM. However there are some cases where the UI makes a decision and there is a large processing requirement, this is done at the WCF or even in stored procedures. I actually prefer procs for this but am finding the WCF and C#/Linq manipulation is fairly simple.
You can't beat a stored proc for sheer grunt whan there is a lot of data to crunch.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I would prefer the UI talking to the service, which in turn talks to the BL approach.
This article[^] ought to be of some interest to you.
|
|
|
|
|
Is it by any means possible to bind a single listview to two seperate observable collections? So, for example the first column is from collection A and the second column from collection B.
If so, how?
|
|
|
|
|
No you can't. What happens if the collections change independently of each other with one collection havin rows added while the other has rows removed?
|
|
|
|
|
No you cannot.
Databinding allows only one data source at a time.
|
|
|
|
|
I have a application written in WPF, C#. There are some settings of different modules of the application which I wanted to store, so that when application is launched, I can restore those settings.
I am thinking of using XML file and writing the settings through XML reader. I am using 'Application.CommonAppDataPath' to store the settings.
Is there a better way to implement this feature in WPF application and that can support Windows 7?
Also, as modules gets added to the application, settings get added to the file. What is the best design to handle addition of settings in future?
Please let me know the correct forum, If I have posted the query in wrong forum.
|
|
|
|
|
No need to hand job anything. Its already built into .NET for you for free. In solution explorer, expand the Properties folder and double click on "Settings.settings". Set up your application settings in that designer.
In your code, you'll access them like:
Properties.Settings.Default.<property name> = blah;
to save, you'd do:
Properties.Settings.Default.Save();
they'll be auto-loaded when your app is loaded.
There are some annoying details to get everything working in the real world, but this will get you started .
|
|
|
|
|
Thanks for the response. However, I am looking for clean way of loading/saving the application preferences in a loosely coupled manner. I am using MVVM architecture for my application and there are some global settings and some local settings pertaining to a module.
|
|
|
|
|
LMAO. How is one line of code not clean? This is perfectly appropriate for MVVM. Your VM would simply initialize its properties from the Properties.Settings.Default.<propname>. If you are too lazy for that , I guess you could write some reflection based code in your ViewModelBase to auto initialize the properties from the user settings. Seems like over engineering IMO though.
|
|
|
|
|
If your storage is fairly temporary, then you might want to consider Isolated Storage as an option.
Using this, you can store settings in memory. Remember thought that these settings can be cleared when the user so wants.
See this[^] for a fairly simple example.
|
|
|
|
|
Thanks Abhinav, however i am looking for some clean way of handling user preferences. Please refer my previous post for more information.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
[EDITED: removed extra backslash from first example. It was copy/paste error]
I am trying to open a WPF window from VB6. I have a .NET 4.0 dll that has four WPF windows and several C# classes in it. Three of the WPF windows open without any errors. The fourth keeps giving me "Run-time error '-2146233087 (80131501)': Automation Error" when InitializeComponents() is called.
I believe it has something to do with what is in the XAML code. Here is an abridged version of what is in the windows that work:
<Window>
<Grid>
<CustomTextBox />
<CustomTextBox />
<Label />
<Label />
</Grid>
</Window>
The three windows using the above format have one method, ShowWindow(), exposed so I can display it from VB6 (no comments about I could have overridden the Show() or ShowDialog() methods please).
Here is the XAML for the window that is not working:
<Window>
<Window.Resources>
<XmlDataProvider x:Key="configdata"/>
<XmlDataProvider x:Key="servodata"/>
</Window.Resources>
<Grid>
<TabControl>
<TabItem>
<Grid>
<ScrollViewer>
<TabControl ItemsSource="{Binding Source={StaticResource configdata}, XPath=PROGRAM/CONFIG_PAGE}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=@page_title}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<toolkit:DataGrid ItemsSource="{Binding XPath=DATA}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</ScrollViewer>
</Grid>
</TabItem>
<TabItem>
<Grid>
<TabControl>
<TabItem>
<Grid>
<toolkit:DataGrid ItemsSource="{Binding Source={StaticResource configdata}, XPath=IO/Inputs/Input}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=METRIC_VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</TabItem>
<TabItem>
<Grid>
<toolkit:DataGrid ItemsSource="{Binding Source={StaticResource configdata}, XPath=IO/Outputs/Output}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=METRIC_VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</TabItem>
</TabControl>
</Grid>
</TabItem>
<TabItem>
<Grid>
<toolkit:DataGrid ItemsSource="{Binding Source={StaticResource servodata}, XPath=DATA}">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding XPath=DESCRIPTION}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=VALUE}"/>
<toolkit:DataGridTextColumn Binding="{Binding XPath=METRIC_VALUE}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</TabItem>
</TabControl>
<Button/>
<Button />
</Grid>
</Window>
The Interface for this window has the same ShowWindow() method plus a boolean property exposed.
I have a tester app with this dll to show the windows and make sure they work before putting them on the VB6 machine. I have ran it on the VB6 machine and the big window works fine. It accesses the XML files it needs to, writes to them, reads from the registry. It all works fine.
I have been working on this for 3 days now and cannot figure out what is wrong. Originally none of the windows would work, but I figured out that my regasm command line was missing the /tlb option. Again, all the other windows work fine and this one works when opened with the tester executable, just not the VB6 executable.
Any help is appreciated.
Brad
Deja Moo - When you feel like you've heard the same bull before.
modified 27-Jan-12 14:43pm.
|
|
|
|
|
I'm not sure if it's just a typo on your part or not but your ending shouldn't have the second backslash.
|
|
|
|
|
Thanks, but I don't see the second backslash you are referring to, but I bet it's a typo. The form shows fine when ran through the .NET test application.
Nevermind, I see it now. It has been correct. The first window is the one that shows without problems. I'm having problems displaying the second example.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|