/// <summary> /// Creates an instance of the type /// </summary> /// <param name="applicationContext">ApplicationContext</param> /// <param name="options">Options instance</param> public LocalProxy(ApplicationContext applicationContext, LocalProxyOptions options) { OriginalApplicationContext = applicationContext; var currentServiceProvider = OriginalApplicationContext.CurrentServiceProvider; Options = options; if (Options.UseLocalScope && OriginalApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Client && OriginalApplicationContext.IsAStatefulContextManager) { // create new DI scope and provider _scope = OriginalApplicationContext.CurrentServiceProvider.CreateScope(); currentServiceProvider = _scope.ServiceProvider; // set runtime info to reflect that we're in a logical server-side // data portal operation, so this "runtime" is stateless and // we can't count on HttpContext var runtimeInfo = currentServiceProvider.GetRequiredService <IRuntimeInfo>(); runtimeInfo.LocalProxyNewScopeExists = true; } CurrentApplicationContext = currentServiceProvider.GetRequiredService <ApplicationContext>(); _portal = currentServiceProvider.GetRequiredService <Server.IDataPortalServer>(); }
/// <summary> /// Creates an instance of the type /// </summary> /// <param name="applicationContext">ApplicationContext</param> /// <param name="options">Options instance</param> public LocalProxy(ApplicationContext applicationContext, LocalProxyOptions options) { ApplicationContext = applicationContext; Options = options; if (Options.CreateScopePerCall) { // create new DI scope and provider _scope = ApplicationContext.CurrentServiceProvider.CreateScope(); var provider = _scope.ServiceProvider; // create and initialize new "server-side" ApplicationContext and manager var parentContext = applicationContext; var ctx = new Csla.Core.ApplicationContextManager(); ctx.SetClientContext(parentContext.ClientContext, parentContext.ExecutionLocation); ctx.SetUser(parentContext.User); ApplicationContext = provider.GetRequiredService <ApplicationContext>(); ApplicationContext.ContextManager = ctx; } _portal = ApplicationContext.CurrentServiceProvider.GetRequiredService <Server.IDataPortalServer>(); }