/// <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); }
/// <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); }