This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I'm just diving in to my first ever .NET project and I’ve been watching this series of videos (http://www.polymorphicpodcast.com/shows/mv-patterns/) to get up to speed with MVP/MVC patterns. It has certainly opened my eyes to a different methodology of coding, that’s for sure. I feel like I’ve been coding in the dark ages for the last 10 years ! It’ll probably take me another couple of run throughs to understand the implementation, but the basics seem to have got through to the grey matter. Anyway, I’m probably being a bit lazy here, and no doubt more investigation would yield the answers I’m looking for, but will the Lightspeed entities be able to plug in to this sort of pattern, and if so, are there any examples available of how this might be achieved ? Many thanks Paul |
|
|
Ooops, apologies for all the spurious characters before the link, I didn't preview the post. Is there anyway to edit a post after it's been made ? |
|
|
I've fixed the content in your first post, so don't worry about that :-) LightSpeed absolutely will work happily with an MVC/MVP pattern and many of the patterns that we use in LightSpeed help facilitate this easily. We do have an MVC example in the installer which targets a web application however it uses the ASP.NET MVC Framework and if you're not targetting the web or planning to use ASP.NET MVC this pay not be the best example for you. Are you planning on using an existing framework to help you or just hand code it all (it's not that hard to do the latter to be honest, but if you had one in mind we could probably offer better guidance)? Kind regards, John-Danie |
|
|
Hi JD, It's going to be a Winforms app and at this stage I was just going to roll my own using the stubs provided by the website link I posted. I figured that for the first part of the project anyway, which is not going to have too many objects, it would be a good way to learn how the MVC pattern is implemented.
Cheers Paul |
|
|
OK, so I've copied some code and changed it a bit and have a very basic demo running using some dummy objects (Reports) to be displayed on a form (have shown in a tree view and a grid). I now want to have a bash and plugging some Lightspeed objects in, but I'm not sure where to start. Below is the form code,service layer interface and the Report object declaration. I've left out the implementation of the IReportService interface and the implementation of the presentation layer. The IReportListView interface comes from the presentation layer. Is it just a case of replacing the current Report object with a Lightspeed entity, then changing the code in the implementation of the ReportService interface to get the details from the database, or are there Lightspeed methods/classes that would replace some of the bits of code here ? Apologies if that's a bit vague , am still getting to grip with things, and many thanks in advance for any pointers {:o)
public partial class ReportForm : Form , IReportListView //can't find easy way to bind at the mo, so just loop through objects to fill tree view. ---------------------------------------------------------------------------------------------------------------------------------- namespace AoteaCentralCSharp.ServiceLayer ---------------------------------------------------------------------------------------------------------------------------------- namespace AoteaCentralCSharp.BusinessLayer |
|
|
Hello Paul, Yes, you would want to implement Report as an Entity. (And consequently, ReportID would disappear in favour of the Entity-supplied Id property.) You could also implement the "report service" as a repository (see IRepository and possibly RepositoryBase / UnitOfWorkScopeBase). We would usually have methods such as GetAllReports() return an IList<Report> rather than a ReportCollection, because this fits more neatly with the LightSpeed UnitOfWork.Find method: public IList<Report> GetAllReports() But you can certainly have it return a custom collection type by using the Find overload that performs the Find into an existing collection rather than returning a new collection. E.g.: public ReportCollection GetAllReports() This enables you to add your own business logic or helper methods to ReportCollection. Note that you will need to set up an appropriate LightSpeedContext and either call CreateUnitOfWork or (as shown above) use a UnitOfWorkScopeBase (for WinForms, a PerThreadUnitOfWorkScope is the one to go for, though this may need rethinking if you are doing retrieval on a worker thread and processing on a UI thread). Have a read through Walkthroughs > QuickStart in the help file for information about creating LightSpeed entities and using the LightSpeedContext class. If you are using VS2008 then you can also use the designer to help with entity definitions. Let us know if this answers your questions. |
|
|
Many thanks for that. I will have a dig around in the examples today and have a go at plugging everything in and see how I get on ! |
|
|
OK, I think I'm in over ny head here {:o( I'm new to C# and implementing interfaces and abstract classes and so on, and cannot work out how to implement the Repository, let alone link it in to the MVC stuff. I'm wondering if I should just ditch the MVC pattern for the first project which would simplify the code, but make updating/adding later down the line more buggy probably. Below is the code for the Presentation Layer that implements the ReportCollection object from before. Should the IReportService interface be replaced by a class that derives from UnitOfWorkScopeBase (and if so, how ??), or am I waaay off base ?!! I'm going to work on something else for a bit and get back to this on Monday. Many apologies for bombarding you guys with what are quite possibly stupid questions ! -------------------------------------------------------------------------------------------------------------------------------------------------------- namespace AoteaCentralCSharp.PresentationLayer |
|
|
Have you looked at the ASP.NET MVC sample? Although that is obviously focused on a Web scenario, it should give you some idea of how the model, view and controller fit together, how to implement a repository (it's easier than you think!) and where the repository sits within the architecture. The Poker sample also follows the model-view-controller structure, though again it is Web-based and it is a bit of a hasty port from LightSpeed v1. As previously noted, IReportService looks from what I've seen like it would be replaced by / implemented as a repository (e.g. class ReportRepository : IReportService). It would NOT be replaced by a class that derives from UnitOfWorkScopeBase. The job of a UnitOfWorkScopeBase is to hold an appropriately-scoped "current" unit of work -- appropriately being e.g. per-request in a Web scenario, or per-thread in a Windows scenario. I.e. its job is to worry about scopes and lifetimes, whereas IReportService's job is to worry about getting reports to the application without it having to worry about database access plumbing. Thus an implementation of IReportService will *use* an IUnitOfWork, and probably manage that unit of work via a UnitOfWorkScopeBase. But those classes do not *replace* IReportService. Here's a possible outline: public interface IReportService : IRepository public class ReportRepository : RepositoryBase<UnitOfWork>, IReportService And in your controller: PerThreadUnitOfWorkScope<UnitOfWork> scope = new PerThreadUnitOfWorkScope<UnitOfWork>(lightSpeedContext); Does that clarify how the bits fit together? If the repository and scope stuff remains confusing then don't worry about it too much. Just forget about the repository and scope classes, implement your IReportService directly in terms of a UnitOfWork, and manage the creation and lifecycle of that UnitOfWork yourself. (This could be as simple as creating the UOW during application startup and just using the same one across the whole lifespan of the app.) To be clear, IUnitOfWork is the central workhorse of LightSpeed -- all the repository and scope stuff is just helpers, the former for hiding IUnitOfWork from the app code, the latter for automating the creation and disposal of IUnitOfWork objects. I wouldn't give up on MVC/MVP just yet -- I know you have taken on a huge learning burden for this project and I think you are right to be willing to jettison bits if the going gets too hard -- better to compromise and succeed than to fail with your purity intact -- but it is pretty early in your learning cycle and from what I remember about your project timescales you still have a bit of time to wrap your head around it! |
|
|
Thanks heaps for that Ivan. I'd forgotten about the ASP sample, and had not looked since it was ASP, but will have another look. Have just made a cuppa and got some chocolate ("Whittakers Peanut Slab" mmmmm) and have embarked on some other code I've got to do for the moment, but will get back to this hopefully with a clear head on Monday. Sometimes it's better to do something completely different (Crystal Reports - arrgghh!) and have another bash later IMHO. Thanks for your time Paul |
|