silk Discussions Rss Feedhttp://silk.codeplex.com/discussionssilk Discussions Rss DescriptionNew Post: 'System.Data.Entity.Database.DefaultConnectionFactory' is obsoletehttp://silk.codeplex.com/discussions/577306<div style="line-height: normal;">Hello.
<br />
<br />
I need your help to solve this problem.
<br />
<br />
In trying to build the project, the following error occurs:
<br />
Warning as Error 26 Error: 'System.Data.Entity.Database.DefaultConnectionFactory' is obsolete. '&quot;The default connection factory Should be in September in the config file or using the DbConfiguration class (See <a href="http://go.microsoft.com" rel="nofollow">http://go.microsoft.com</a> / fwlink / LinkId = 260 883) &quot;'C: \ Users \ 12076634 \ Documents \ Visual Studio 2010 \ Projects \ Project Silk-RTM \ MileageStats \ MileageStats.Data.SqlCe \ RepositoryInitializer.cs 46 13 MileageStats.Data.SqlCe
<br />
<br />
install all prerequisites listed in the documentation.<br />
</div>jpcv19Fri, 09 Jan 2015 17:21:30 GMTNew Post: 'System.Data.Entity.Database.DefaultConnectionFactory' is obsolete 20150109052130PNew Post: Models in different layershttp://silk.codeplex.com/discussions/440626<div style="line-height: normal;"><strong>DCherubini wrote:</strong><br />
<blockquote>
Hi,<br />
<br />
The documentation describes the handlers in the domain project as &quot; <em>a set of classes that implement the core behavior of the application</em> ,&quot; where each handler is in charge of performing only one specific action. The controllers in the application delegate the logic of interacting with the domain layer to those handlers. Based on my understanding, the difference with the services is that they seem to be used only to obtain information from the domain without modifying it.<br />
</blockquote>
They have handlers that actually modifying domain, e.g. AddFillupToVehicle, CreateVehicle and DeleteVehicle etc.
<br />
But I see that one handler never executes any other handler, so they are really independent from each other.
<br />
So it looks like that it will be better to move business logic to Services, e.g. UserServices when one handler should execute another one. For example I see that in UserServices they have method GetOrCreateUser which uses GetUserByClaimedIdentifier or CreateUser methods from UserServices.
<br />
<br />
That's how I see it. Thoughts?
<br />
Thanks!<br />
</div>sergeypeSat, 27 Sep 2014 18:44:34 GMTNew Post: Models in different layers 20140927064434PNew Post: Roadmap or future of project Silkhttp://silk.codeplex.com/discussions/292460<div style="line-height: normal;">Check the link
<br />
<a href="http://msdn.microsoft.com/en-us/library/ff921348.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ff921348.aspx</a>
<br />
<br />
it is still on and it will be. There is no near future retirement for project silk.<br />
</div>naishadhTue, 10 Jun 2014 14:11:56 GMTNew Post: Roadmap or future of project Silk 20140610021156PNew Post: Handlers and a service-classeshttp://silk.codeplex.com/discussions/539422<div style="line-height: normal;">Hi,
<br />
<br />
Although from the side of the &quot;consumer&quot; (for example a controller consuming a service or a handler) they appear to be similar, the difference is how they are implemented.
<br />
<br />
In my opinion, a <strong><em>service</em></strong> allows to wrap certain parts of the application that should be loosely coupled from the rest of the components and provide a easy way to consume the functionality of those parts. A service might store information that could be then shared and modified in other components of the application. Also, it's not uncommon for a service to perform some kind of initialization before it can be consumed. An example of this case could be the repositories, where you are separating the data access layer from the controllers. The controllers doesn't know how to access the database, only how to consume the service.
<br />
<br />
The <strong><em>handlers</em></strong> used in Silk (not to be confused with the APS.NET handlers) have a more dumb role instead. They basically provide a collection of &quot;functions&quot; that could be executed in any controller. In contrast to services, they role is not to &quot;decouple&quot; functionality that should not be in the controllers and in fact I think that most code container in the handlers could be put directly in the controllers without breaking any separation concern. This is similar to when we separate a long function into smaller ones; it allows you to have smaller controllers which are more readable and promotes code reusability between controllers.
<br />
<br />
So basically, in Silk a handler is like a simple collection of reusable functions (like a helper) while a service provides access to more complex components.
<br />
<br />
Thanks,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniWed, 19 Mar 2014 18:53:01 GMTNew Post: Handlers and a service-classes 20140319065301PNew Post: Handlers and a service-classeshttp://silk.codeplex.com/discussions/539422<div style="line-height: normal;">I have a couple of questions of handlers and service-classes.
<br />
<br />
What is the difference between the two? From one post i understood that there isn't any. If so why the separation?
<br />
<br />
The handlers seem to contain only CRUD operations and validations. Is this the role of a handler? If I would add a class lets say Messaging and it would be responsible for sending messages, would it be okay to make it into a handler. Would it follow the architectural guidelines?
<br />
<br />
When creating handlers the goal is to make them as loosely coupled as possible. But as the application grows you end up having handlers with a lot of dependencies and they act like facades, How wold this be implemented according to project silk guidelines? Is it acceptable that a handler has many dependencies or would it be better to create a facade layer? <br />
</div>huotariTue, 18 Mar 2014 23:47:32 GMTNew Post: Handlers and a service-classes 20140318114732PNew Post: IUnitOfWork in project silk http://silk.codeplex.com/discussions/450678<div style="line-height: normal;">They did it so they could use Unity to inject a DBContext into the repositories. DBContext doesn't otherwise implement an interface, although it does have a SaveChanges method already so technically already implements IUnitOfWork. But they really need to DI that reference to the DBContext into the repositories, so they wrote a hack. The whole BaseRepository falls apart if the IUnitOfWork implementation you give it isn't a DbContext.
<br />
<br />
So in essence, while pretending to be using DI to loosely couple the repositories and the DBContext, they just mask the tight coupling. The worst of both worlds!<br />
</div>gilmaeTue, 17 Sep 2013 11:28:48 GMTNew Post: IUnitOfWork in project silk 20130917112848ANew Post: Whats controlling dbContext instances in IUnitOfWork http://silk.codeplex.com/discussions/451739<div style="line-height: normal;">Hi,
<br />
<br />
In <strong>MileageStats</strong> the configuration for the type mappings used by <strong>Unity</strong> are set in the <strong>unity.config</strong> file (or <strong>unity.debug.config</strong> file depending your launch configuration). In that file you can find the following mapping for the <strong>IUnitOfWork</strong> interface:<br />
<div style="color:Black;background-color:White;"><pre>
<span style="color:Blue;">&lt;</span><span style="color:#A31515;">type</span> <span style="color:Red;">type</span><span style="color:Blue;">=</span><span style="color:Black;">&quot;</span><span style="color:Blue;">MileageStats.Data.IUnitOfWork, MileageStats.Data</span><span style="color:Black;">&quot;</span> <span style="color:Red;">mapTo</span><span style="color:Blue;">=</span><span style="color:Black;">&quot;</span><span style="color:Blue;">MileageStats.Data.SqlCe.MileageStatsDbContext, MileageStats.Data.SqlCe</span><span style="color:Black;">&quot;</span><span style="color:Blue;">&gt;</span>
<span style="color:Blue;">&lt;</span><span style="color:#A31515;">lifetime</span> <span style="color:Red;">type</span><span style="color:Blue;">=</span><span style="color:Black;">&quot;</span><span style="color:Blue;">perRequest</span><span style="color:Black;">&quot;</span> <span style="color:Blue;">/&gt;</span>
<span style="color:Blue;">&lt;/</span><span style="color:#A31515;">type</span><span style="color:Blue;">&gt;</span>
</pre></div>Note the <em>&quot;perRequest&quot;</em> setting. This type (defined also in the <strong>unity.config</strong> file) sets a <strong>UnityHttpContextPerRequestLifetimeManager</strong> as the lifetime manager for the <strong>MileageStatsDbContext</strong> instance. As the name implies, this lifetime manager always provides the same instance of <strong>MileageStatsDbContext</strong> to any class for the current request. For example, each repository created to handle a request made by the client will receive the same context upon construction.
<br />
<br />
Thanks,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniTue, 30 Jul 2013 18:43:44 GMTNew Post: Whats controlling dbContext instances in IUnitOfWork 20130730064344PNew Post: Performance issuehttp://silk.codeplex.com/discussions/451484<div style="line-height: normal;">Hi,
<br />
<br />
The following note, took from <a href="http://msdn.microsoft.com/en-us/library/hh404093.aspx#sec8" rel="nofollow">Chapter 11 - Server-Side Implementation - Implementing the Repository Pattern</a> explains the design decisions took by the team regarding this topic:<br />
<h1></h1>
<blockquote>
The <strong>IReminderRepository</strong> interface returns collections as <strong>IEnumerable&lt;T&gt;</strong>, rather than <strong>IList&lt;T&gt;</strong> or <strong>ICollection&lt;T&gt;</strong>. This was an intentional design choice to prevent the direct addition of entities to the collections. To create a new reminder, the developer must use the <strong>Create</strong> method.<br />
In Mileage Stats, the implementation of the <strong>IReminderRepository</strong> calls <strong>ToList</strong> before returning the <strong>IEnumerable&lt;T&gt;</strong>. This is to ensure that the query is executed inside the repository. If <strong>ToList</strong> was not called, then the repository would return an <strong>IQueryable&lt;T&gt;</strong> and the database would not be accessed until something iterated over the <strong>IQueryable&lt;T&gt;</strong> object. The problem with returning an <strong>IQueryable&lt;T&gt;</strong> is that a developer consuming the API is likely to assume that the query has already executed and that you are working with the results. If you iterate over the query more than once, it will result in multiple calls to the database.<br />
If you specifically want your repository to return queries instead of results, use the <strong>IQueryable&lt;T&gt;</strong> on the interface in order to make your intention explicit.<br />
</blockquote>
<h1></h1>
I hope this helps in understanding the architecture of the project and the design decisions behind the <strong>Mileage Stats</strong> implementation.
<br />
<br />
Regards,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniMon, 29 Jul 2013 20:26:53 GMTNew Post: Performance issue 20130729082653PNew Post: Whats controlling dbContext instances in IUnitOfWork http://silk.codeplex.com/discussions/451739<div style="line-height: normal;">When Silk are using repositories in handler-classes, repositories take a IUnitOfWork in the constructor witch unity makes sure gets an instance of MileageStatsDbContext injected. But when multiple repositories are used, what is it that controls that the same dbContext is used in all repositories?
<br />
<br />
What is it that makes it a &quot;unit&quot; of work?
<br />
<br />
It seems they are missing the point of using UnitOfWork because they are calling this.UnitOfWork.SaveChanges(); in Create, Update and Delete method of the repository classes, in that way it cannot be a &quot;unit&quot; of work only one change at a time.
<br />
<br />
Does anyone have another point of view, because to me it looks like they are using unitofwork just to make the application more complex, and they like to understand what others dont?<br />
</div>Andreas12345678Mon, 29 Jul 2013 11:49:19 GMTNew Post: Whats controlling dbContext instances in IUnitOfWork 20130729114919ANew Post: Performance issuehttp://silk.codeplex.com/discussions/451484<div style="line-height: normal;">Hi,
<br />
<br />
Thanks for your prompt reply.
<br />
<br />
For functions in data layer, the function <strong>ToList()</strong> is called before return. For example, <br />
<pre><code>public IEnumerable&lt;Reminder&gt; GetOverdueReminders(int vehicleId, DateTime forDate, int odometer)
{
return this.GetDbSet&lt;Reminder&gt;()
.Where( r =&gt; (r.VehicleId == vehicleId) &amp;&amp; (r.DueDate &lt; forDate || r.DueDistance &lt; odometer) &amp;&amp; !r.IsFulfilled)
.ToList();
}
</code></pre>
Executing <strong>ToList()</strong> would cause the query to execute immediately.
<br />
<br />
In VehicleController.JsonDetails, <strong>Take(3)</strong> would be carried out against the data in memory. i.e. more than enough data would be retrieved from DB<br />
<pre><code> var overdue = Using&lt;GetOverdueRemindersForVehicle&gt;()
.Execute(id, DateTime.UtcNow, vehicle.Odometer ?? 0)
.Take(3);
</code></pre>
Thanks!<br />
</div>hermanchanMon, 29 Jul 2013 01:22:05 GMTNew Post: Performance issue 20130729012205ANew Post: Performance issuehttp://silk.codeplex.com/discussions/451484<div style="line-height: normal;">Hi,
<br />
<br />
I believe that usually, when you implement a design pattern to maintain testability, scalability, etc. it's common to experience a small decrement in the application's performance when compared to an implementation without any pattern. How significant this performance decrement will be depends of the context of your application; for most scenarios it should be minimal.
<br />
<br />
However, in this particular case, I do not understand why returning an <strong>IEnumerable&lt;&gt;</strong> would impact in the performance of the application at all. Could you elaborate a little more about how this is affecting the performance and what implementation would you prefer to return instead?
<br />
<br />
Thanks,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniFri, 26 Jul 2013 17:34:47 GMTNew Post: Performance issue 20130726053447PNew Post: Performance issuehttp://silk.codeplex.com/discussions/451484<div style="line-height: normal;">Hello. I found lots of filtering are performed after getting all data from DB. Because the repository layer and business layer all return IEnumerable&lt;&gt;. Does it affect the performance a lot?
<br />
<br />
However, if not return IEnumerable&lt;&gt;, these layers will become difficult to test.
<br />
<br />
Is the current design a performance tradeoff to achieve testabilty?
<br />
<br />
Thanks.<br />
</div>hermanchanFri, 26 Jul 2013 08:41:55 GMTNew Post: Performance issue 20130726084155ANew Post: IUnitOfWork in project silk http://silk.codeplex.com/discussions/450678<div style="line-height: normal;">Hi,<br />
<br />
I believe that maybe the interface was planned to provide an abstraction layer between the data context and the repositories (besides the <strong>BaseRepository</strong>, no sub repository implementation access the <strong>MileageStatsDbContext</strong> directly.) Hence, if you need to change the class in charge of the database context you would only need to refactor the <strong>BaseRepository</strong> class. <br />
<br />
However, it doesn't seems that the <strong>IUnitOfWork</strong> interface provide a deep abstraction level in the application. Especially since the repositories use a <strong>Entity Framework</strong> <strong>DbSet</strong> object to work with the database. Hence the repositories are &quot;abstracted&quot; of the <strong>MileageStatsBdContext</strong> implementation, but not from <strong>Entity Framework</strong>.<br />
<br />
As you said, if such kind of abstraction is not useful in an application, using a <strong>Context</strong> property in <strong>MileageStatsBdContext</strong> could be enough.<br />
<br />
Regards,<br />
<br />
Damian Cherubini<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniMon, 22 Jul 2013 18:57:34 GMTNew Post: IUnitOfWork in project silk 20130722065734PNew Post: IUnitOfWork in project silk http://silk.codeplex.com/discussions/450678<div style="line-height: normal;">Hi
<br />
<br />
I project silk they are using IUnitOfWork in the BaseRepository class. Is that really necessary? The BaseRepository is adjusted to use with EF dbContext so its not an abstraction for the context in order to be able to change context.
<br />
If I'm not mistaken they could have used a property &quot;context&quot; of MileageStatsDbContext and gotten the same result.
<br />
<br />
What's the point of using IUnitOfWork like they do?<br />
</div>Andreas12345678Sat, 20 Jul 2013 12:58:35 GMTNew Post: IUnitOfWork in project silk 20130720125835PNew Post: IServiceLocator in project Silkhttp://silk.codeplex.com/discussions/450067<div style="line-height: normal;">Thanks for a good answer.
<br />
<br />
They could have done this by using only the unity container.
<br />
<br />
Msdn says:
<br />
<br />
&quot;In the following situations, it may be appropriate for you to use the IServiceLocator:
<br />
•You are an independent software vendor (ISV) designing a third-party service that needs to support multiple containers.
<br />
•You are designing a service to be used in an organization where they use multiple containers.&quot;
<br />
<br />
Project Silk is not using multiple containers so maybe its a unnecessary layer of abstraction.<br />
</div>Andreas12345678Sat, 20 Jul 2013 12:42:00 GMTNew Post: IServiceLocator in project Silk 20130720124200PNew Post: IServiceLocator in project Silkhttp://silk.codeplex.com/discussions/450067<div style="line-height: normal;">Hi,
<br />
<br />
I believe that the main objective of the <strong>Using</strong> method is to simplify the creation of the handlers. Let's take for example the <strong>ReminderController</strong> and the <strong>AddReminderToVehicle</strong> handler. If you want to create an instance of the handler you will find that its constructor needs two parameters, which means that the <strong>ReminderController</strong> will need to know those parameters in order to create the handler. What is more, the controller requires several other handlers as well, so it will need to know the parameters to construct all of the handlers it uses.
<br />
<br />
In order to avoid this, the controllers delegate the creation of the handlers to the <strong>ServiceLocator</strong>. Finally, by encapsulating the logic to retrieve the handler from the <strong>ServiceLocator</strong> in the <strong>Using</strong> method, the syntax of the controller becomes simpler and easier to read.
<br />
<br />
Thanks,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniTue, 16 Jul 2013 17:34:46 GMTNew Post: IServiceLocator in project Silk 20130716053446PNew Post: IServiceLocator in project Silkhttp://silk.codeplex.com/discussions/450067<div style="line-height: normal;">In project Silk they use IServiceLocator to get an instance of &quot;Handler&quot; classes, what is the benefit of using this?
<br />
<br />
I mean in the controllers it looks like this:
<br />
<br />
Using&lt;GetOverdueRemindersForUser&gt;().Execute(CurrentUserId);
<br />
<br />
If they are to hard code the class name they could have gotten an instace of the class the normal way.
<br />
<br />
Is it just to save one line of code or is there another benefit?<br />
</div>Andreas12345678Mon, 15 Jul 2013 17:15:50 GMTNew Post: IServiceLocator in project Silk 20130715051550PNew Post: IQueryable in IEnumerablehttp://silk.codeplex.com/discussions/441960<div style="line-height: normal;">Hi,
<br />
<br />
Based on my understanding, it is as the documentation says. This is due to a quality of the object oriented programming languages named <strong>Polymorphism</strong>.
<br />
<br />
Basically, the <strong>IQueryable</strong> interface inherits from the <strong>IEnumerable</strong> interface. This allows you to sent a reference of type <strong>IEnumerable</strong> to an <strong>IQueryable</strong> implementation, return an <strong>IQueryable</strong> &quot;as it was&quot; an <strong>IEnumerable</strong>, etc. Hence, without the <strong>ToList</strong> invocation (which returns a <strong>List</strong> which is an <strong>IEnumerable</strong> implementation), an <strong>IQueryable</strong> would be returned instead &quot;masked&quot; as an <strong>IEnumerable</strong>.
<br />
<br />
When storing an <strong>IQueryable</strong> using a reference of type <strong>IEnumerable</strong> you can invoke its methods like you would on an <strong>IEnumerable</strong> but the logic that will be executed is the one defined in the <strong>IQueryable</strong> implementation, e. i. the behavior of the object will still be the one of an <strong>IQueryable</strong>.
<br />
The same applies to the <strong>IEnumerable</strong> extension methods because, basically, an extension method is an static method that uses the original methods of the object to work.
<br />
<br />
You can find more information about <strong>Polimorphism</strong> in the following MSDN article:<br />
<ul>
<li>
<a href="http://msdn.microsoft.com/en-us/library/ms173152.aspx" rel="nofollow">Polymorphism (C# Programming Guide)</a><br />
</li>
</ul>
Regards,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a><br />
</div>DCherubiniMon, 29 Apr 2013 20:14:04 GMTNew Post: IQueryable in IEnumerable 20130429081404PNew Post: IQueryable in IEnumerablehttp://silk.codeplex.com/discussions/441960<div style="line-height: normal;">Hi
<br />
<br />
In the documentation of Project silk it says following:
<br />
<br />
&quot;In Mileage Stats, the implementation of the iReminderRepository calls Tolist before returning the iEnumerable&lt;T&gt;. This is to ensure that the query is executed inside the repository. If Tolist was not called, then the repository would return an iQueryable&lt;T&gt; and the database would not be accessed until something iterated over the iQueryable&lt;T&gt; object.&quot;
<br />
<br />
A code expample:<br />
<pre><code> public IEnumerable&lt;Reminder&gt; GetRemindersForVehicle(int vehicleId)
{
return this.GetDbSet&lt;Reminder&gt;()
.Where(v =&gt; v.VehicleId == vehicleId)
.ToList();
}
</code></pre>
Does that mean that even though the result is returned like IEnumerable, this would just be a container for a IQueryable, and if ToList() would not be called than one could be making calls on the IEnumerable as if it was a IQueryable?
<br />
<br />
Is this really right? It sounds wrong to me. If you where to make calls on the IEnumerable&lt;Reminder&gt;, that is returned if ToList isn't called, it would be the extension methods of IEnumerable that would be used and not IQueryable.
<br />
<br />
How can they clame that the function is returning a iQueryable&lt;T&gt; if ToList is not called, how is that possible?
<br />
<br />
It would be right if the method was returning a iQueryable&lt;T&gt; but it dosen't.<br />
</div>Andreas12345678Mon, 29 Apr 2013 14:01:43 GMTNew Post: IQueryable in IEnumerable 20130429020143PNew Post: Models in different layershttp://silk.codeplex.com/discussions/440626<div style="line-height: normal;">Hi,
<br />
<br />
The documentation describes the handlers in the domain project as &quot; <em>a set of classes that implement the core behavior of the application</em> ,&quot; where each handler is in charge of performing only one specific action. The controllers in the application delegate the logic of interacting with the domain layer to those handlers. Based on my understanding, the difference with the services is that they seem to be used only to obtain information from the domain without modifying it.
<br />
<br />
I believe you can find more information about the Domain layer implemented in Mileage Stats, in the following section of the documentation, where the handlers and models it uses are described:<br />
<ul>
<li>
<a href="http://msdn.microsoft.com/en-us/library/hh404093.aspx#sec12" rel="nofollow">Chapter 11 - Server-Side Implementation - Creating a Business Services Layer</a><br />
</li>
</ul>
I hope this helps,
<br />
<br />
Damian Cherubini
<br />
<a href="http://blogs.southworks.net/dcherubini" rel="nofollow">http://blogs.southworks.net/dcherubini</a> <br />
</div>DCherubiniMon, 22 Apr 2013 19:03:39 GMTNew Post: Models in different layers 20130422070339P