예제 #1
0
        /// <summary>
        /// Add CSLA .NET services for use by the application.
        /// </summary>
        /// <param name="services">ServiceCollection object</param>
        /// <param name="options">Options for configuring CSLA .NET</param>
        public static IServiceCollection AddCsla(this IServiceCollection services, Action <CslaOptions> options)
        {
            // Custom configuration
            var cslaOptions = new CslaOptions(services);

            options?.Invoke(cslaOptions);

            // capture options object
            services.AddScoped((p) => cslaOptions);

            // ApplicationContext defaults
            services.AddScoped <ApplicationContext>();
            RegisterContextManager(services);

            // Runtime Info defaults
            services.TryAddScoped(typeof(IRuntimeInfo), typeof(RuntimeInfo));

            cslaOptions.AddRequiredDataPortalServices();

            // Default to using LocalProxy and local data portal
            var proxyInit = services.Where(i => i.ServiceType.Equals(typeof(IDataPortalProxy))).Any();

            if (!proxyInit)
            {
                cslaOptions.DataPortal((options) => options.UseLocalProxy());
            }

            return(services);
        }
예제 #2
0
        /// <summary>
        /// Configures services to provide CSLA Blazor server support
        /// </summary>
        /// <param name="config">CslaOptions instance</param>
        /// <param name="options">Options object</param>
        /// <returns></returns>
        public static CslaOptions AddServerSideBlazor(this CslaOptions config, Action <BlazorServerConfigurationOptions> options)
        {
            var blazorOptions = new BlazorServerConfigurationOptions();

            options?.Invoke(blazorOptions);

            // minimize PropertyChanged events
            config.PropertyChangedMode(ApplicationContext.PropertyChangedModes.Windows);

#if NET5_0_OR_GREATER
            var managerType = Type.GetType("Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor,Csla.AspNetCore");
            if (managerType is null)
            {
                throw new TypeLoadException("Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor,Csla.AspNetCore");
            }
            config.Services.AddScoped(typeof(IContextManager), managerType);
#endif

            // use Blazor viewmodel
            config.Services.TryAddTransient(typeof(ViewModel <>), typeof(ViewModel <>));
            if (blazorOptions.UseCslaPermissionsPolicy)
            {
                config.Services.AddTransient <IAuthorizationPolicyProvider, CslaPermissionsPolicyProvider>();
                config.Services.AddTransient <IAuthorizationHandler, CslaPermissionsHandler>();
            }
            return(config);
        }
        /// <summary>
        /// Set up the data portal by applying the configuration that has been built
        /// </summary>
        /// <param name="config">The configuration to use in setting up the data portal</param>
        internal static void AddRequiredDataPortalServices(this CslaOptions config)
        {
            var services = config.Services;

            // LocalProxy must always be available to support RunLocal
            services.TryAddTransient((p) => new Channels.Local.LocalProxyOptions());
            services.AddTransient <Channels.Local.LocalProxy, Channels.Local.LocalProxy>();

            // Data portal API defaults
            services.TryAddTransient(typeof(IDataPortal <>), typeof(DataPortal <>));
            services.TryAddTransient(typeof(IChildDataPortal <>), typeof(DataPortal <>));
            services.TryAddTransient <IDataPortalFactory, DataPortalFactory>();
            services.TryAddTransient <IChildDataPortalFactory, ChildDataPortalFactory>();

            services.TryAddScoped(typeof(IAuthorizeDataPortal), config.DataPortalServerOptions.AuthorizerProviderType);
            foreach (Type interceptorType in config.DataPortalServerOptions.InterceptorProviders)
            {
                services.AddScoped(typeof(IInterceptDataPortal), interceptorType);
            }
            services.TryAddScoped(typeof(IObjectFactoryLoader), config.DataPortalServerOptions.ObjectFactoryLoaderType);
            services.TryAddScoped(typeof(IDataPortalActivator), config.DataPortalServerOptions.ActivatorType);
            services.TryAddScoped(typeof(IDataPortalExceptionInspector), config.DataPortalServerOptions.ExceptionInspectorType);

            services.TryAddScoped <DataPortalExceptionHandler>();
            services.TryAddTransient(typeof(IDataPortalServer), typeof(DataPortal));
            services.TryAddScoped <InterceptorManager>();
            services.TryAddTransient <DataPortalSelector>();
            services.TryAddTransient <SimpleDataPortal>();
            services.TryAddTransient <FactoryDataPortal>();
            services.TryAddTransient <DataPortalBroker>();
            services.TryAddSingleton(typeof(Server.Dashboard.IDashboard), config.DataPortalServerOptions.DashboardType);
        }
예제 #4
0
        /// <summary>
        /// Add CSLA .NET services for use by the application.
        /// </summary>
        /// <param name="services">ServiceCollection object</param>
        /// <param name="options">Options for configuring CSLA .NET</param>
        public static IServiceCollection AddCsla(this IServiceCollection services, Action <CslaOptions> options)
        {
            // Custom configuration
            var cslaOptions = new CslaOptions(services);

            options?.Invoke(cslaOptions);

            // capture options object
            services.AddScoped((p) => cslaOptions);

            // ApplicationContext defaults
            services.AddScoped <ApplicationContext>();
            RegisterContextManager(services);

            // Data portal API defaults
            services.TryAddTransient(typeof(IDataPortal <>), typeof(DataPortal <>));
            services.TryAddTransient(typeof(IChildDataPortal <>), typeof(DataPortal <>));

            // LocalProxy is always necessary to support RunLocal
            services.TryAddTransient((p) => new Channels.Local.LocalProxyOptions());
            services.AddTransient <Channels.Local.LocalProxy, Channels.Local.LocalProxy>();
            // Server-side data portal is always necessary to support RunLocal
            cslaOptions.DataPortal().AddServerSideDataPortal();

            // Default to using LocalProxy and local data portal
            var proxyInit = services.Where(i => i.ServiceType.Equals(typeof(IDataPortalProxy))).Any();

            if (!proxyInit)
            {
                cslaOptions.DataPortal().UseLocalProxy();
            }

            return(services);
        }
예제 #5
0
 /// <summary>
 /// Registers services necessary for Windows Forms
 /// </summary>
 /// <param name="config">CslaConfiguration object</param>
 /// <returns></returns>
 public static CslaOptions WithBlazorWebAssembly(this CslaOptions config)
 {
     config.Services.TryAddTransient(typeof(ViewModel <>), typeof(ViewModel <>));
     config.Services.TryAddSingleton <IAuthorizationPolicyProvider, CslaPermissionsPolicyProvider>();
     config.Services.TryAddSingleton <IAuthorizationHandler, CslaPermissionsHandler>();
     config.Services.TryAddSingleton(typeof(Csla.Core.IContextManager), typeof(Csla.Core.ApplicationContextManagerStatic));
     Csla.Channels.Http.HttpProxy.UseTextSerialization = true;
     return(config);
 }
예제 #6
0
        /// <summary>
        /// Configures services to provide CSLA AspNetCore support
        /// </summary>
        /// <param name="config">CslaOptions instance</param>
        /// <param name="options">Options object</param>
        /// <returns></returns>
        public static CslaOptions AddAspNetCore(this CslaOptions config, Action <AspNetCoreConfigurationOptions> options)
        {
            var localOptions = new AspNetCoreConfigurationOptions();

            options?.Invoke(localOptions);
            config.Services.TryAddTransient((p) => new Channels.Local.LocalProxyOptions {
                CreateScopePerCall = false
            });
            return(config);
        }
예제 #7
0
        /// <summary>
        /// Registers services necessary for Windows Forms
        /// environments.
        /// </summary>
        /// <param name="config">CslaConfiguration object</param>
        /// <param name="options">XamlOptions action</param>
        /// <returns></returns>
        public static CslaOptions AddWindowsForms(this CslaOptions config, Action <WindowsFormsOptions> options)
        {
            var xamlOptions = new WindowsFormsOptions();

            options?.Invoke(xamlOptions);

            // use correct mode for raising PropertyChanged events
            ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Windows;
            return(config);
        }
예제 #8
0
 /// <summary>
 /// Registers services necessary for Blazor WebAssembly.
 /// </summary>
 /// <param name="config">CslaConfiguration object</param>
 /// <returns></returns>
 public static CslaOptions AddBlazorWebAssembly(this CslaOptions config)
 {
     config.Services.TryAddTransient(typeof(ViewModel <>), typeof(ViewModel <>));
     config.Services.TryAddScoped <IAuthorizationPolicyProvider, CslaPermissionsPolicyProvider>();
     config.Services.TryAddScoped <IAuthorizationHandler, CslaPermissionsHandler>();
     config.Services.TryAddScoped(typeof(Csla.Core.IContextManager), typeof(Csla.Blazor.WebAssembly.ApplicationContextManager));
     config.Services.TryAddScoped(typeof(AuthenticationStateProvider), typeof(Csla.Blazor.Authentication.CslaAuthenticationStateProvider));
     Csla.Channels.Http.HttpProxy.UseTextSerialization = true;
     return(config);
 }
예제 #9
0
        /// <summary>
        /// Configures services to provide CSLA AspNetCore support
        /// </summary>
        /// <param name="config">CslaOptions instance</param>
        /// <param name="options">Options object</param>
        /// <returns></returns>
        public static CslaOptions AddAspNetCore(this CslaOptions config, Action <AspNetCoreConfigurationOptions> options)
        {
            var localOptions = new AspNetCoreConfigurationOptions();

            options?.Invoke(localOptions);
#if NET5_0_OR_GREATER
            config.Services.AddScoped <ActiveCircuitState>();
            config.Services.AddScoped(typeof(CircuitHandler), typeof(ActiveCircuitHandler));
#endif
            config.Services.AddScoped(typeof(IContextManager), typeof(ApplicationContextManagerHttpContext));
            return(config);
        }
예제 #10
0
        /// <summary>
        /// Registers services necessary for Xaml-based
        /// environments.
        /// </summary>
        /// <param name="config">CslaConfiguration object</param>
        /// <param name="options">XamlOptions action</param>
        /// <returns></returns>
        public static CslaOptions AddXaml(this CslaOptions config, Action <XamlOptions> options)
        {
            var xamlOptions = new XamlOptions();

            options?.Invoke(xamlOptions);

            // use correct mode for raising PropertyChanged events
            ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml;

            config.Services.TryAddTransient(typeof(ViewModel <>), typeof(ViewModel <>));
            return(config);
        }
예제 #11
0
        /// <summary>
        /// Configures services to provide CSLA Blazor server support
        /// </summary>
        /// <param name="config">CslaOptions instance</param>
        /// <param name="options">Options object</param>
        /// <returns></returns>
        public static CslaOptions AddServerSideBlazor(this CslaOptions config, Action <BlazorServerConfigurationOptions> options)
        {
            var blazorOptions = new BlazorServerConfigurationOptions();

            options?.Invoke(blazorOptions);

            // use Blazor viewmodel
            config.Services.TryAddTransient(typeof(ViewModel <>), typeof(ViewModel <>));
            if (blazorOptions.UseCslaPermissionsPolicy)
            {
                config.Services.AddTransient <IAuthorizationPolicyProvider, CslaPermissionsPolicyProvider>();
                config.Services.AddTransient <IAuthorizationHandler, CslaPermissionsHandler>();
            }
            return(config);
        }
예제 #12
0
 /// <summary>
 /// Extension method for CslaDataPortalConfiguration
 /// </summary>
 /// <param name="config"></param>
 /// <param name="options"></param>
 public static DataPortalClientOptions DataPortal(this CslaOptions config, Action <DataPortalClientOptions> options)
 {
     options?.Invoke(config.DataPortalClientOptions);
     return(config.DataPortalClientOptions);
 }
예제 #13
0
 /// <summary>
 /// Creates an instance of the type.
 /// </summary>
 /// <param name="options"></param>
 public DataPortalClientOptions(CslaOptions options)
 {
     CslaOptions = options;
 }
예제 #14
0
 /// <summary>
 /// Extension method for CslaDataPortalConfiguration
 /// </summary>
 public static DataPortalClientOptions DataPortal(this CslaOptions config)
 {
     return(DataPortal(config, null));
 }
예제 #15
0
 /// <summary>
 /// Extension method for CslaSerializationConfiguration
 /// </summary>
 public static CslaOptions Serialization(this CslaOptions config, Action <SerializationOptions> options)
 {
     options?.Invoke(config.SerializationOptions);
     return(config);
 }
예제 #16
0
 /// <summary>
 /// Registers services necessary for Windows Forms
 /// environments.
 /// </summary>
 /// <param name="config">CslaConfiguration object</param>
 /// <returns></returns>
 public static CslaOptions AddWindowsForms(this CslaOptions config)
 {
     return(AddWindowsForms(config, null));
 }
예제 #17
0
 /// <summary>
 /// Registers services necessary for Xaml-based
 /// environments.
 /// </summary>
 /// <param name="config">CslaConfiguration object</param>
 /// <returns></returns>
 public static CslaOptions AddXaml(this CslaOptions config)
 {
     return(AddXaml(config, null));
 }
예제 #18
0
 /// <summary>
 /// Extension method for CslaDataConfiguration
 /// </summary>
 public static CslaOptions Data(this CslaOptions config, Action <DataOptions> options)
 {
     options?.Invoke(config.DataOptions);
     return(config);
 }
예제 #19
0
 /// <summary>
 /// Configures services to provide CSLA Blazor server support
 /// </summary>
 /// <param name="config">CslaOptions instance</param>
 /// <returns></returns>
 public static CslaOptions AddServerSideBlazor(this CslaOptions config)
 {
     return(AddServerSideBlazor(config, null));
 }
예제 #20
0
 /// <summary>
 /// Configures services to provide CSLA AspNetCore support
 /// </summary>
 /// <param name="config">CslaOptions instance</param>
 /// <returns></returns>
 public static CslaOptions AddAspNetCore(this CslaOptions config)
 {
     return(AddAspNetCore(config, null));
 }
예제 #21
0
 /// <summary>
 /// Extension method for CslaSecurityConfiguration
 /// </summary>
 public static CslaOptions Security(this CslaOptions config, Action <SecurityOptions> options)
 {
     options?.Invoke(config.SecurityOptions);
     return(config);
 }