MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

MVCxUI? advice. #586

Open grahamblandford opened 6 years ago

grahamblandford commented 6 years ago

I just seem to be going around in circles trying to adopt CSLA for web development using MVC.

No matter which branch I take in order to understand how to implement a half decent web interface using ASP.Net MVC, Razor, etc., it seems that there are no CURRENT examples of that within this CSLA community(?)

I had previously purchased the "Using CSLA" eBook series, but that isn't really helping as they refer to an older version of MVC, for which it seems there are no updated samples. There is no updated "MVC5UI/MVC6UI" even though the solution and associated projects seem to be the most relevant of all samples I have come across.

And yet the most recent ProjectTracker sample projects don't offer an ASP.Net MVC project. There are Xamarin projects, WPF, WebForms and even WinForms, but still nothing for MVC.

One of the attractions for me to CSLA when I first started using it all those years ago, was that even a novice .Net developer as I was at the time was able to take the examples shown and implement a custom solution by applying the samples and going from there.

It now feels like only experienced Web developers (which I am not, and hence am looking for some familiar ground) are entertained now.

I appreciate that most of the community contribute their time and events for free - and this is by no means a criticism of them. But I'm just airing my frustrations at not being able to move forward by leveraging a library that served me well for so many years, without pulling teeth.

If the expectation is that I already be a competent Web developer in order to figure things out for myself, then I'll accept that, and just go on my merry way. Having exposure to ASP.NET/MVC/Razor texts using Microsoft, Pluralsight resources, etc., I'm no closer to coming up with a way of implementing a comprehensive framework that I've had with CSLA over the years. And frankly I just wonder if I just don't have "it" and should hang up my boots and look for alternative ways to earn a living.

If anyone has any decent suggestions for a way forward, would love to hear them.

Once again, sorry if this post comes across as a self-indulgent rant. That's not my aim, I'm just looking to extend my love affair with CSLA without wasting so much more time following dead ends.

Thanks,

Graham

CSLA version: 4.7.100

rockfordlhotka commented 6 years ago

I appreciate your desire to use CSLA! And I really wish I had more time to put into building samples!

It is true that I've been spending a lot of time with Xamarin lately, outside the context of CSLA, and therefore it has been easier for me to do Xamarin stuff inside the context of CSLA as well.

My current work hasn't involved anything beyond dabbling with ASP.NET Core Razor pages. Just enough to think that I really like them a lot, but I just haven't been able to dig in.

ghost commented 6 years ago

I can probably put together a sample based on an implementation of mine although it might take a little time. Whether that completely follows the eBook and stuff is another issue but I've been using CSLA with MVC for a few projects (even converting WebForms). I suppose feedback on whether I'm doing anything wrong would also be welcome. The one caveat to all of this is that I have not moved into the NS2.0/.Core arena yet.

rockfordlhotka commented 6 years ago

I think ASP.NET Core running on either full .NET or .NET Core is (a) basically the same; (b) super-useful if you have time @fujiiface !!

grahamblandford commented 6 years ago

Thanks for the reply guys!

I certainly appreciate your response @rockfordlhotka and completely understand that your focus is elsewhere. Xamarin is certainly an area I would like to embroil myself in, as I see a number of opportunities to extend my existing applications AND new ones into the mobile arena. But I think I should learn to walk (crawl some might say) before I can run!

Honestly @fujiiface, that would be fantastic. And even if you could get it to the stage of having the authentication in place and a sample of a single parent/child relationship (Project/ProjectResource)(?), with some business/authorization rules, I think that would get me on track - and I'd be quite happy to spend the time completing the sample for the CSLA community! CSLA has served me very well over the years, and if I can give something back as I learn, I happily will!

Look forward to further development on this!

Thanks again, Graham

rockfordlhotka commented 6 years ago

fwiw (which might not be a lot yet), I am now working on a Razor pages project for a non-profit. I'm using this as an excuse to really learn Razor pages and how they work with CSLA.

Just at the moment all it has is a bunch of screens to display data from tables, so nothing exciting, but it does use CSLA 😄

https://github.com/rockfordlhotka/mcmreporting

grahamblandford commented 6 years ago

All steps in the right (another) direction for sure.

I think what's blurred some lines in moving forward is how razor was included as part of the MVC3 methodology, but razor templates are only loaded by default is you select a .NET CORE project. Quote confusing...

I've decided to try and follow the documentation for the MVC3UI project creation step-by-step and see if I can't translate that to an ASP.NET MVC5 project. I'll keep you posted on progress.

Thanks again!

rockfordlhotka commented 6 years ago

This work item will surely help: https://github.com/MarimerLLC/csla/issues/900

If you look at the mcmreporting app, I now have a full implementation of the basic index/create/edit/delete cycle for a single BusinessBase object: https://github.com/rockfordlhotka/mcmreporting/tree/master/mcmreporting/Pages/School

Update: The Case functionality is now largely complete, which is a more sophisticated CRUD scenario with what amounts to a type of child object.

This directory includes a SchoolEditBinder.cs file, which contains what has turned into the custom model binder I'm putting into CSLA. I haven't gotten to binding collections yet, but this binds a single object, which is a good step in the right direction.

rockfordlhotka commented 6 years ago

If you are using Razor Pages, please consider using the upcoming 4.7.200 release (#593), as I could use any testing or feedback on the new CslaModelBinder implementation.

grahamblandford commented 6 years ago

Thanks Rocky. I’ll absolutely do that. Didn’t get a chance to move forward on the MVC route this past weekend, but hoping to do that early this week.

ajj7060 commented 6 years ago

I'll just chime in, as I did use Csla and MVC3 pretty extensively (and maybe MVC4). I think one reason you haven't been seeing much new is that really not much new has changed; I was using Razor page, MVC and Csla, and while both frameworks have advanced, I don't think the basics have changed at all.

I AM currently using Csla to power a recent version of a WebAPI project, and in that regard nothing much has changed with how I use controllers and Csla.

rockfordlhotka commented 6 years ago

As I built the new CslaModelBinder @ajj7060 , I will say that the underlying tech in ASP.NET Core is completely different. The model binding is totally different from what it was in "regular" ASP.NET MVC.

I do think you are right though, when using MVC in ASP.NET Core not a lot is different for the UI developer.

If you use Razor Pages then it is a whole different thing - and imo a simpler thing. But the page lifecycle, model binding mechanisms, and various other aspects are quite different from raw MVC.

ajj7060 commented 6 years ago

Thanks @rockfordlhotka , I haven't used the newer MVC (and certainly not anything Core related), so that is good information to know!

ghost commented 6 years ago

@rockfordlhotka I've been looking at your mcmreporting project and I have a couple questions regarding it and how it could apply to MVC 5. Using RaceEthnicities Create.cshtml.cs file as a reference:

  1. You defined the ROLB and Info classes in the same file. I've always seen this defined in separate files. I realize everyone has their way of doing things but do you think this is something we should do moving forward, for consistency sake?

  2. In your CreateModel, I notice you do not call a factory method such as ListRaceEthnicities and instead call DataPortal.FetchAsync directly. Is this a pattern we should be following instead of creating functions within the ROLB?

I'm borrowing some of what I see to see how it fits into what I am currently working on and it seems pretty straight forward but I wonder if there are any disadvantages/advantages you can speak to? For reference, most of my new code references the Using CSLA 4 encapsulated invocation model way of doing things.

Without running your project, I have been looking through the sample and Razor Pages seem pretty great if I'm understanding the programming model correctly. Cant wait to dig into this more 👍

rockfordlhotka commented 6 years ago

HI @fujiiface - I am definitely not following all the best practices as I'm learning Razor Pages. Some of that is intentional, some is just a lack of focus on the business layer and more on learning Razor Pages.

  1. I often do this while prototyping, then split things into separate files later - though sometimes I wonder why they aren't just in one file, because they go together as a pair anyway. I think you mention the most important thing though: consistency. I'm not sure one is better than the other, as long as the app's code is consistent.
  2. This is something I frequently do if I don't anticipate the need for caching. In this particular case I wanted to get things working and then I'm going to explore the way their scaffolding builds out code with a DbContext - specifically I want to figure out if a rough CSLA equivalent to a DbContext (ObjectContext? DataPortalContext?) would be helpful.
    1. In any case, I've been migrating away from static factory methods over the past few years, because they make mocking and DI nearly impossible.
    2. This app could definitely benefit from caching the large number of read-only reference collections rather than reloading them from the database each time, so a factory method would make sense - but again, I want to explore this DbContext scaffolding to see how/if that fits.
  3. I generally use encapsulated invocation, which is what I'm doing in this app - though I didn't bother with a provider model in the DAL because I don't anticipate the need to switch to a different db - the PostgreSQL database already exists, so that's what'll be used.
  4. I agree that Razor Pages is pretty cool. I think I'm starting to get the hang of them now - and I see where I've dug myself into a bit of a hole with my naming conventions between (what amount to) viewmodels vs my domain model types. I might clean that up, but certainly if I had it to do over again I'd develop a convention to name viewmodels vs models more clearly.
grahamblandford commented 6 years ago

Sorry, been MIA the last couple of days to respond to the various comments as my focus shifted to another paying project. But I am slowly moving forward on the MVC5 project. I do have to take a look at the missing persons application though. I ultimately decided to plow through the MVC route because my understanding was that Razor is now "paired" with Core and not MVC - as the older MVC version and the MVC3UI project had done. Is that not a correct statement? I know that if I create a new proejct/solution in VS, it doesn't reference Razor when selecting an MVC project.

Ultimately, I'd like the option of using both, so I don't feel I'm wasting my time with the non-Razor route.

rockfordlhotka commented 6 years ago

I don't know for sure, but I do know that all the MVC projects I've done over the past few years have used Razor-based views. I can't remember the last time I created anything without using Razor. So I am quite confident that you can use both - standard controllers and Razor views. That's not the same as Razor Pages, but the Razor part is the same.

grahamblandford commented 6 years ago

OK. Thanks @rockfordlhotka

Hoping things become a little clearer as I move forward...

rockfordlhotka commented 6 years ago

In addition to the mcmreporting app (which is a real thing), I worked through the common scenario of editing a collection "in-place" in a page. Something that seems like it should be so easy, but isn't...

In this case, the new CslaModelBinder in 4.7.200 supports binding to a root BusinessListBase, and then if you create Index and Create pages you can get (what I think) is a really nice in-place edit experience for the collection.

Here's the gist: https://gist.github.com/rockfordlhotka/a8b3253a8ee3b318ce6d30f733529075

Perhaps better, I decided to add it to the Samples folder https://github.com/MarimerLLC/csla/tree/master/Samples/NET/cs/CslaModelBinderDemo

And I decided to blog about it to make the approach more easily digestible. http://www.lhotka.net/weblog/InPlaceListEditingInRazorPages.aspx

ghost commented 6 years ago

@rockfordlhotka If I start work on an MVC example, where would want the project?

grahamblandford commented 6 years ago

Hi guys,

Was there any movement on the inclusion of an MVC example?, especially as I understand we've moved away from .Net Core now with the advent of 4.8.1.

I'm trying to pick this up again, and establish a starting point to prove to my client that we have a viable framework to re-write our current application (Windows Forms with CSLA) as it is reaching end of life.

I noticed there is a CSLAMVC sample project in the distribution - but I'm unable to build it(?) seems to be referencing the wrong System.Web.MVC?

I did look at the Blazor and MCMreporting applications and although I managed to get them working, I think they've raised more questions than I had to start with in that again, they each only use some of the features/implementations of csla, as well as adding complexities to my already limited knowledge of web technology.

For what it's worth, I still think the ProjectTracker solution is the only way I am going to be able to understand how CSLA fits into a modern web-based solution. It has a number of projects that are relevant which employ the business classes, Dals, identity implementation, etc. that I am familiar with from CSLA 2., and it's a real shame that there is no working MVC example project that will enable me to move forward.

Honestly, with a little direction on how to implement the identity model and a simple list/CRUD interface for an object, I'd be willing to complete the sample project so that others might benefit from it.

Thanks.

UPDATE: I managed to get the CSLA MVC sample project running - installed the latest version of ASPNET.MVC (5.2...) ... this project seems more like what I'm after, although need to figure out how to create a real Repo that pulls from a SQL server database..

grahamblandford commented 6 years ago

Upon further digging (and once again the strong desire to just quit and consider a different career path again), this has me thinking that maybe the CslaMVC project might get me going in the right direction.

It seems to have enough examples with similarities to what I do using the older version of CSLA in terms of business objects, rule checking/authorization/user identity and crud functionality - certainly a starting point.

What would be extremely useful is if I could get maybe an example of how I would create a repo to an actual datasource (sql server), rather than the xml mock data that is currently used.

Also, the principal/identity model just doesn't make a great deal of sense to me in it's implementation here - other than the authorization pieces ... again, an example of retrieving the credentials from an actual datasource would maybe benefit me here.

I'm trying to cludge together as much knowledge from the various samples and projects that are currently on offer, but really not making much progress. It just seems that each example uses a somewhat different method of implementing CSLA, when it seemed to be much more straightforward in previous iterations: I basically have TWO layers - business objects (which also handles database calls) and a UI layer.

Any assistance would be greatly appreciated.

rockfordlhotka commented 6 years ago

@fujiiface an MVC example would go in the /Samples folder at the top level - I'm slowly removing all the subfolders now that everything is moving to .NET Standard and .NET Core.

rockfordlhotka commented 6 years ago

@grahamblandford Have you looked at those mcmreporting links I put in the thread earlier?

grahamblandford commented 6 years ago

I did @rockfordlhotka and the objects look very familiar. But I couldn't get it running(?) I suspect because I have no real datasource?

If I could resolve that, this would actually make for a great base for what I need - albeit I'd have to move to SQL Server and add some authentication .... but baby steps..

rockfordlhotka commented 6 years ago

Ahh, I thought the SQL script was in the repo, but it was not. I've added it - at least I hope it is the current/latest - that's the problem with it not being in the repo, is that I'm not 100% sure...

https://github.com/rockfordlhotka/mcmreporting/blob/master/mnMissingChildren.sql

grahamblandford commented 6 years ago

That would explain it!

Thanks Rocky. I'll grab it and see if I can make it work. Will let you know!

Graham

grahamblandford commented 6 years ago

OK, still trying to get this up and running with the data @rockfordlhotka

I re-scripted your scripts to MSSQL, and have a local database all set, but then realized I would have to figure out how to modify the connection code to use MSSQL (something I have to do anyway, but I'd like to review the functionality of what you have before I move on that).

I have installed an instance of PostGreSQL (9.6). And have created the objects ( I've never used PostGreSQL previously.)

I've installed on localhost/default port and into a database/schema = mcmreporting,.. and have set this in my appsettings: "AllowedHosts": "*", "ConnectionStrings": { //"mcmreportingContext": "Server=(localdb)\mssqllocaldb;Database=mcmreportingContext-f7241d6d-f5c1-44d5-b2be-68cce7d98a22;Trusted_Connection=True;MultipleActiveResultSets=true", "mcmreportingContext": "\"Server=127.0.0.1;Port=5432;Database=mcmreporting;User Id=postgre;Password=mypassword" }

But connection returns 'null' each time. Any ideas what I'm doing wrong?

grahamblandford commented 6 years ago

UPDATE:

Using SQL Server I've managed to run the application with some data - now I'm off to the races!

I figured out the connection string issue. But changed the entry in Startup to:

Csla.ApplicationContext.LocalContext["ConnectionString"] = Configuration["ConnectionStrings:mcmreporting"];

which ties to the settings:

{ "Logging": { "LogLevel": { "Default": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "mcmreporting": "Data Source=THINKPADW10P\SQLDEV16;Database=mcmreporting;Integrated Security=True" } }

Not sure how the original would have worked but there you have it.

Now to dig :)