﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - How to Use Crosslight v2 with Constructor Injection on ViewModels</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-with-Constructor-Injection-on-ViewModels/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to Use Crosslight v2 with Constructor Injection on ViewModels</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-with-Constructor-Injection-on-ViewModels/</link><pubDate>Fri, 24 Oct 2014 06:24:07 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;You can safely pass the repository class for the ViewModel by using Injection of Container technique.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;The contructor of ExpenseListViewModel should look like following:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public ExpenseListViewModel()
{
    ...
    this.SourceItems = this.Repository.GetAll().ToObservable();
    ...
}

private IItemRepository Repository
{
    get
    {
        if (Container.Current.CanResolve&amp;lt;IItemRepository&amp;gt;())
            return Container.Current.Resolve&amp;lt;IItemRepository&amp;gt;();
        else
            return new ItemRepository(); // for designer support
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;The IItemRepository object is registered in the contructor of AppService, such as shown in the following snippet code:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public sealed class MyInventoryAppService : ApplicationServiceBase
{
    public MyInventoryAppService(IApplicationContext context)
        : base(context)
    {
        Container.Current.Register&amp;lt;IItemRepository, ItemRepository&amp;gt;().WithLifetimeManager(new ContainerLifetime());
        ...
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;ItemListViewModel.cs and AppService.cs (MyInventory.Core) implements the same technique and  can be used as reference. Hope this help.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 with Constructor Injection on ViewModels</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-with-Constructor-Injection-on-ViewModels/</link><pubDate>Wed, 22 Oct 2014 18:18:18 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hi Yudi,&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Well, the reason why we're asking is because we are trying to construct our view models with parameters, instead of using property injections. Since we are using old school WCF to retrieve data from the server, we are implementing it this way while we haven't updated to your Enterprise architecture yet, because we started from&amp;nbsp;&lt;b&gt;Crosslight v1&lt;/b&gt;. In which it was easier to reference a WCF web service to just grab data by using operation contracts. Or we thought it was easier, and now we are running into problems.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;pre&gt;public class ExpenseListViewModel : EditableListViewModelBase&amp;lt;ExpenseItem&amp;gt;{
    private readonly IExpenseRepository _expenseRepository;

    public ExpenseListViewModel(IExpenseRepository expenseRepository)
    {
        this._expenseRepository = expenseRepository;
    }

    ...
}&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Now, if this implementation is not a good practice based on Crosslight's architecture, please let us know how we can implement CRUD operations on remote data without using WebAPI. We already have operation contracts within the WCF web service based on CRUD operations (e.g. GetExpenseByID, GetAllExpenses, DeleteExpense, RemoveExpense, etc.). &amp;nbsp;That said, we also have implemented a class within the client (mobile app) that acts as an adapter, which implements asynchronous methods such as GetByIdAsync, GetAllAsync, DeleteAsync. Now, the only piece that's missing is the link between Crosslight and the adapter, which acts as a repository class for the view models.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Do we need to implement&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;font face="Courier New"&gt;&lt;b&gt;&lt;span style="color: rgb(51, 51, 51);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 100, 164);"&gt;IEditableDataRepository&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&amp;nbsp;interface with&amp;nbsp;&lt;span style="color: rgb(51, 100, 164); font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;b&gt;EditableListViewModelBase&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;? We were looking at the&amp;nbsp;&lt;/span&gt;&lt;a href="http://git.intersoftpt.com/projects/CROS/repos/samples/browse/MyInventory_MasterDetail" target="_blank"&gt;&lt;b&gt;MyInventory_MasterDetail&lt;/b&gt;&lt;/a&gt;&lt;span style="font-size: 10pt;"&gt;&amp;nbsp;sample, but turns out to be for local files. There is the&amp;nbsp;&lt;b&gt;MyInventory_WebAPI&lt;/b&gt;&amp;nbsp;sample, but this was designed for the Crosslight's Enterprise architecture. Is there any samples that implement other REST services and/or WCF web services, aside from WebAPI? We would very much like to have such examples.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Again, many thanks! As always.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 with Constructor Injection on ViewModels</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-with-Constructor-Injection-on-ViewModels/</link><pubDate>Wed, 22 Oct 2014 04:56:39 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Could you please provide us with more information regarding your scenario which involves constructor injection on ViewModel? Who knows there is a chance to implement the scenario by using different approach/techniques.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 with Constructor Injection on ViewModels</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-with-Constructor-Injection-on-ViewModels/</link><pubDate>Tue, 21 Oct 2014 18:10:22 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hey Guys,&lt;br&gt;&lt;br&gt;Is it possible to use constructor injection on view models, aside from using property injection? Just a thought, please let us know. Thanks!&lt;/p&gt;</description></item></channel></rss>