MarimerLLC / cslaforum

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

Fluent configuration #657

Open rockfordlhotka opened 5 years ago

rockfordlhotka commented 5 years ago

I have put a preliminary implementation of a fluent configuration API into master (planning on it being in 4.9.0). With this new API you can do things on app startup like this:

      new CslaConfiguration()
        .PropertyChangedMode(Csla.ApplicationContext.PropertyChangedModes.Windows)
        .PropertyInfoFactory("MyProject.MyFactory, MyProject")
        .RuleSet("Default")
        .UseReflectionFallback(false)
        .DataPortal.AuthenticationType("MyProject.MyAuthenticator, MyProject")
        .DataPortal.AutoCloneOnUpdate(false)
        .DataPortal.DataPortalActivator(new TestActivator())
        .DataPortal.DataPortalProxyFactory("MyProject.MyProxyFactory, MyProject")
        .DataPortal.DataPortalReturnObjectOnException(true)
        .DataPortal.DefaultDataPortalProxy(typeof(Csla.DataPortalClient.HttpProxy).AssemblyQualifiedName, "https://example.com/test")
        .DataPortal.ExceptionInspectorType("MyProject.MyExceptionInspector, MyProject")
        .DataPortal.FactoryLoaderType("MyProject.MyFactoryLoader, MyProject")
        .DataPortal.InterceptorType("MyProject.MyInterceptor, MyProject")
        .DataPortal.ServerAuthorizationProvider("MyProject.MyAuthorizer, MyProject")
        .Data.DefaultTransactionIsolationLevel(Csla.TransactionIsolationLevel.ReadCommitted)
        .Data.DefaultTransactionTimeoutInSeconds(90)
        .Security.PrincipalCacheMaxCacheSize(123);

Not that you have to set all these values (nor should you!!), but this demonstrates the flow of the API.

You can also define mappings for types or resource IDs to data portal proxies. In the following example I set the default proxy, and two specific proxies, one for a type, the other for types decorated with the new DataPortalServerResource attribute:

      new CslaConfiguration()
        .DataPortal.DefaultDataPortalProxy(typeof(Csla.DataPortalClient.HttpProxy).AssemblyQualifiedName, "https://default.example.com/test")
        .DataPortal.DataPortalProxyDescriptors(new List<Tuple<string, string, string>>
        {
          Tuple.Create(typeof(TestType).AssemblyQualifiedName, 
                       typeof(Csla.DataPortalClient.HttpProxy).AssemblyQualifiedName, 
                       "https://test.example.com/test").
          Tuple.Create(((int)ServerResources.SpecializedAlgorithm).ToString(),
                       typeof(Csla.DataPortalClient.HttpProxy).AssemblyQualifiedName,
                       "https://specialized.example.com/test")
        });

I welcome thoughts on the API, especially ways to improve it, or mistakes I've made.

rockfordlhotka commented 5 years ago

(already I can see that I don't like the redundant naming of some of those data portal methods)