Replies: 5 comments 16 replies
-
The use of the dataportal is pretty close to what it was, except that it is no longer a static method. You will inject the object into the class. You are also able to create a new object using a factory class that is also injected but usable for creation of new objects. Dependency injection is not optional any more as critical functionality expects authenticated users and there is no way to create a new object using the static methods. I just did a major upgrade of CSLA, .NET 7, and EF 7 and converted my WPF application to Blazor. It's a major undertaking but I am able to stay current with new functionality on the horizon that CSLA 6 will implement. As you know, EF 6 to Core was a major "migration" technically but in truth a rewrite. But without upgrading it would be a nightmare using MS's old technologies. Rocky and Cakemonster can provide way more technical detail and overarching reasons for the CSLA paradigm shift. |
Beta Was this translation helpful? Give feedback.
-
@tabaguley I enjoyed your post and I am in a similar situation, not just because of dependency injection but other reasons as well. Almost all of our projects are currently in Csla 4.xx and I don't see migrating them to Csla 6.xx (or latest version) anytime soon. Our team is ridiculously small and only new projects could 'afford' to direct the latest versions of Csla. |
Beta Was this translation helpful? Give feedback.
-
We really had no choice but to embrace DI thanks to Blazor. It literally doesn't work without DI. In CSLA 5 I tried to support DI without requiring it, which became a blocker for Blazor very quickly. So CSLA 6 requires DI so it can fulfill the core promise of providing a consistently way to build your business logic regardless of your UI or DAL technology choices. At the time it was clear that this would cause some pain, yet there's no way around it. Truly using DI is very much like truly using async/await or generics - you either go all the way or create a mess that would make no one happy in the long run. Hopefully you have found and read the upgrading to CSLA 6 doc? There are some good ways to minimize code changes for existing codebases. Yes, you'll need to update your code, but the updates can be rote and mechanical if you want to take a minimal approach for older UI technologies. If and when you go to Blazor you'll need to make slightly deeper changes, because (again) Blazor is built around DI. In the long run I suspect most folks building .NET UIs will end up using Blazor. Sure, Windows Forms and WPF will remain basically unchanged for (probably) decades, but it'll get hard to find people willing to use those technologies. MAUI might succeed, but I'm personally finding that when I use MAUI it is via the Blazor Hybrid model, so I'm really building the UI in Blazor. There's no doubt that server-side aspnetcore MVC and Razor Pages will remain important, though honestly they also work better with DI than without. If you've been watching the evolution of Blazor for .NET 8, the Unified Blazor ideas that are being floated may make it so we can write server-side code using the Blazor UI model, and then auto-switch to full Blazor once the runtime loads in the browser - some pretty interesting stuff for sure! I guess that's the centerpiece of what I'm saying - if you continue to use legacy UI technologies you can use relatively low-impact techniques to switch to "using DI" without really using DI very much. In the long run though, I think the pressure will continue to mount for organizations to modernize to newer UI technologies, where DI becomes required. (fwiw, you can also use DI in WinForms and WPF; doing so (imo) simplifies or eliminates a lot of UI framework code that we all used to have to write by hand or bring in via a UI framework dependency (MVVM, etc.); I know that's not helpful for existing codebases, but I can say for sure that if I started a greenfield WPF app today I'd use the DI approach to simplify so many things!) |
Beta Was this translation helpful? Give feedback.
-
I personally find DI to be a very useful tool. In my experience good use of DI makes systems much easier to modify - to develop and enhance over time. Gone are the days when you had to change multiple classes to add a new dependency to a lower tier in your application; add it to the constructor of an injected class and it's available where you need it, with minimal effort. It's this nested dependency resolution that is so useful. ClassA uses ClassB uses ClassC, and you need to add a new dependency to ClassC - and it's easy to do by adding it to the constructor of ClassC if ClassA is retrieved from DI. That's a great benefit. DI-based systems are also easier to unit test, in general. I'm not a believer in TDD, but I do believe in the benefits of unit tests. It is possible to build testable systems without DI, but it is quite a lot more difficult. To some extent, I think of it less being about DI and more being about pluggable architectures. I'd say two things with regards your dilemma about using it:
There is a counter argument to point 2 of course - keeping up to date a bit at a time is sometimes easier than a big bang later on. However, I totally feel your pain at this point; the upgrade to CSLA 6 is a big bang in itself, so I'd delay it until you feel more ready for it. That time may come, or it may not, but at the moment you are not in the right mindset to undertake it because you don't appreciate the benefits - and that's totally fine. That's a reasonable decision. The one recommendation I would make is that you try to remain open to changing your mind on that decision in the future. What I have done in the past is kept somewhat abreast of new versions of CSLA, but only upgraded when I felt the benefits outweighed the costs. Upgrades have been rare; many of my systems have kept on trucking for many years (decades) on the version of the framework we started out with. DesiGen hasn't been upgraded to CSLA 6 yet, for example - but it's still working fine at the moment on the older version on which it is based. I have to admit the length of time we can stick on older version might be more problematic in the .NET Core/5/6/7 world (as opposed to .NET Framework). Annual releases of the runtime might make backwards compatibility more problematic, we'll have to wait and see. |
Beta Was this translation helpful? Give feedback.
-
Man do I feel your pain @tabaguley. There's no easy way around it. I am not kidding when I tell you I had the EXACT same frustrations you described. ~1000 business objects to convert and somewhat new to DI and wondering why the hell I needed it anyway. Luckily I had about 80-85% code coverage via an automated business layer test suite so after the conversion to CSLA 6 I had good confidence that all was working if they passed. Anyway, I agree with the advice given. Despite the pain, it is worth it. Upgrade when you need, delay for a while OK, but watch for tech debt and don't get too far behind. Most of my time was spent learning new patterns and playing in a small test project with different ways to get it done. Obviously, the main issue was how to deal with ApplicationContext no longer being static and public! Ugh. So I spent a few weeks learning and experimenting before the big plunge. The actual conversion took a few days of my time to slog through all the .cs files. Like Rocky said, it was mostly rote cut/copy/paste over and over and over while my eyes turned red and I tried to remember to blink every now and then. In the end, other than being madly in love with Blazor SS, I feel the greatest benefit is just being in .NET 6+ and all that brings. The new project format for Visual Studio and the way it properly handles Nuget packages and transient dependencies is just so much cleaner. Take one look at the new .proj file vs the old and you will say "gee where'd all that old confusing crap go!?" The number of your nuget packages in project dependencies will be clean and much smaller and easily identified in a hierarchical format. Anyway, good luck and as Nike used to say "Just Do It" :-) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been reading through numerous posts, both within the CSLA group here, as well as other non-CSLA groups/posts on the Web. At this point in time, there is a critical question I cannot answer: What problem does Dependency Injection actually solve??
Apparently, I am not alone in posing this question. Clearly, there are many proponents of its use. But all I see is a nightmare of unnecessary and excessive parameters, interfaces, objects being passed around, etc. …just to “fix” something that wasn’t broken with a new-fangled way of doing things.
Now, I am faced with a critical dilemma: how do I stay current with the CSLA Framework?
Because with dozens of applications built over the years, containing thousands of CSLA-based business objects, and hundreds of thousands of lines of code, there is NO WAY to implement CLSA 6+ without breaking EVERYTHING (and forcing a radical re-write of the entire code base).
Here are a few of the key features that attracted me to CSLA over 20 years ago (yes, I was there at the beginning of CLSA .NET in 2002):
• Object In Charge – Private Constructors; Public Shared/Static Get_() and New_() methods to create or load objects
• Clearly and uniformly defined DataPortal_ Methods
• The ability to use a DataPortal Server (via Configuration) if desired (but not required)
That last bullet point is key to my next question: CSLA did not demand you use a DataPortal Server – you could set one up and use it if desired. Your code would work the same with or without it.
(Even other CSLA features like automatic n-Level Undo may be disabled when not desired: DisableIEditableObject = True)
So my next question: Can CSLA be updated to allow for Dependency Injection if desired (via config settings), but still allow for use of the DataPortal the way it always has been? [One could say, “The way God intended;” but that might be blasphemous.]
Not only would this allow users of CSLA to upgrade without breaking things, but it would also allow the same CLSA codebase to be used in both older (say, WinForms) applications, as well as the new hotrod UIs (like Blazor) – without breaking things or requiring a departure from the norm in how the UI platform is typically used.
(Yes, I’ve reviewed the latest WinForms example for CSLA, and all I can say is, “That is not at all how a WinForms application should be built or function. Just because it can be made to work like an SPA or WPF application does not mean it should be.)
And BTW… My latest Website, running on .NET 7 (and .NET 5 & 6 before that) works perfectly fine using CLSA 5+! Dependency Injection is totally unnecessary for CLSA, even though the site itself uses it.
SO… Is it possible to make Dependency Injection optional? Or must we continue to maintain and use an older, working version of CLSA (5+) if we want to avoid the headache of trying to upgrade?
(I'm also going to post a Poll asking about this, as I'm curious what approach seems best to the community as a whole.)
Beta Was this translation helpful? Give feedback.
All reactions