Using Csla 6 Factory type in Csla 5 #3185
-
I want to make the upgrade from Csla 5 to Csla 6 easier by doing away with the static factory methods and instead use the factory classes with the IDataPortalFactory injected. The idea is to put the following example class in my Csla 5 project and use this in my code. I can then gradually change all the objects. Upgrading to Csla 6 would then be much fewer coding changes once off. Would this be possible? If so, does anyone has suggestions on how to do this?
The calling code should then change from
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There are a couple ways to do the calling code, depending on whether you have DI configured. I would recommend that you do configure DI, and then use a service locator pattern, so that's what I'll discuss here. First, in app startup, ensure DI is configured, and // startup code
services.AddCsla();
services.AddTransient<PersonEdit.Factory>();
// ...
// once you've created the service provider, set your static service locator property
App.ServiceProvider = provider; Then, in your public static ServiceProvider ServiceProvider { get; set; } Then in your calling code where you want to use the factory: var factory = App.ServiceProvider.GetRequiredService<PersonEdit.Factory>();
var person = await factory.GetAsync(personId); This approach provides the easiest migration to full use of DI in the future. |
Beta Was this translation helpful? Give feedback.
There are a couple ways to do the calling code, depending on whether you have DI configured. I would recommend that you do configure DI, and then use a service locator pattern, so that's what I'll discuss here.
First, in app startup, ensure DI is configured, and
UseCsla
is called. Also register your factory types.Then, in your
App
class (or other globally available type) implement the service locator pattern:The…