/// <summary> /// Get instance of a proxy. /// </summary> /// <param name="serviceType"> /// The service type. /// </param> /// <param name="channelFactory"> /// The channel factory. /// </param> /// <returns> /// The proxy object. /// </returns> protected object InstantinateProxy(Type serviceType, Type channelFactory) { Type type; lock (ServicesToContracts) { type = ServicesToContracts[serviceType]; } this.RegisterProxyFactory(type, serviceType, channelFactory); IActivator activator = new SessionActivator(); object[] customAttributes = serviceType.GetCustomAttributes(typeof(ServiceBehaviorAttribute), false); if (customAttributes.Length > 0) { var attribute = (ServiceBehaviorAttribute)customAttributes[0]; if (attribute.InstanceContextMode == InstanceContextMode.Single) { activator = new ApplicationActivator(); } else if (attribute.InstanceContextMode == InstanceContextMode.PerCall) { activator = new RequestActivator(); } } return(activator.Activate(type)); }
static void Main() { ApplicationActivator.UseEnvironment(EnvironmentName.Development).Startup(); try { Console.WriteLine("Accessing the ICacheServiceWithBehavior..."); var service1 = ServiceContainer.GetInstance <ICacheServiceWithBehavior>(); Console.WriteLine("ICacheServiceWithBehavior returns value: " + service1.GetVale("Sample")); Console.WriteLine("Accessing the ICacheServiceWithContractAttribute..."); var service2 = ServiceContainer.GetInstance <ICacheServiceWithContractAttribute>(); Console.WriteLine("ICacheServiceWithContractAttribute returns value: " + service2.GetVale("Sample")); Console.WriteLine("Accessing the ICacheServiceWithFactory..."); var service3 = ServiceContainer.GetInstance <ICacheServiceWithFactory>(); Console.WriteLine("ICacheServiceWithFactory returns value: " + service3.GetVale("Sample")); Console.WriteLine("Accessing the ICacheServiceWithServiceAttribute..."); var service4 = ServiceContainer.GetInstance <ICacheServiceWithServiceAttribute>(); Console.WriteLine("ICacheServiceWithServiceAttribute returns value: " + service4.GetVale("Sample")); Console.WriteLine("Success"); } catch (Exception ex) { Console.Error.WriteLine(ex.GetType().FullName); Console.Error.WriteLine(ex.Message); } Console.ReadLine(); }
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); ApplicationActivator.UseEnvironment(env.EnvironmentName); }
protected override void OnStartup(StartupEventArgs e) { var first = ApplicationActivator.LaunchOrReturn(otherInstance => { MessageBox.Show("got data"); }, e.Args); if (!first) { Shutdown(); } base.OnStartup(e); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var first = ApplicationActivator.LaunchOrReturn(otherInstance => { MessageBox.Show("got data: " + otherInstance.Skip(1).FirstOrDefault()); }, args); if (!first) { return; } Application.Run(new Form1()); }
static async Task Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var first = await ApplicationActivator.LaunchOrReturnAsync(otherInstance => { MessageBox.Show("got data: " + otherInstance.Skip(1).FirstOrDefault()); }); if (!first) { return; } Application.Run(new Form1()); }
public static void Main(string[] args) { // Get the AppDomainManager from the current domain. AppDomainManager domainMgr = AppDomain.CurrentDomain.DomainManager; // Get the ApplicationActivator from the AppDomainManager. ApplicationActivator appActivator = domainMgr.ApplicationActivator; Console.WriteLine("Assembly qualified name from the application activator."); Console.WriteLine(appActivator.GetType().AssemblyQualifiedName); // Get the ActivationArguments from the SetupInformation property of the domain. ActivationArguments activationArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments; // Get the ActivationContext from the ActivationArguments. ActivationContext actContext = activationArgs.ActivationContext; Console.WriteLine("The ActivationContext.Form property value is: " + activationArgs.ActivationContext.Form); Console.Read(); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); ApplicationActivator.UseService(services).Startup(); }
private static int Main(string[] args) { var isFirstInstance = true; Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // This might fix the SEHException raised sometimes. See issue: // https://sourceforge.net/tracker/?func=detail&aid=2335753&group_id=96589&atid=615248 Application.DoEvents(); // child threads should impersonate the current windows user AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal); /* setup handler for unhandled exceptions in non-debug modes */ // Allow exceptions to be unhandled so they break in the debugger #if !DEBUG ApplicationExceptionHandler eh = new ApplicationExceptionHandler(); AppDomain.CurrentDomain.UnhandledException += eh.OnAppDomainException; #endif #if DEBUG && TEST_I18N_THISCULTURE Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(new I18NTestCulture().Culture); Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture; #endif FormWindowState initialStartupState = Win32.GetStartupWindowState(); // if you want to debug the minimzed startup (cannot be configured in VS.IDE), // comment out the line above and uncomment the next one: //FormWindowState initialStartupState = FormWindowState.Minimized; var appInstance = new RssBanditApplication(); Action <string[]> callback = appInstance.OnOtherInstance; try { GuiInvoker.Initialize(); isFirstInstance = ApplicationActivator.LaunchOrReturn(cb => GuiInvoker.Invoke(appInstance.MainForm, () => callback(cb)), args); } catch (Exception /* ex */) { //_log.Error(ex); /* other instance is probably still running */ } //_log.Info("Application v" + RssBanditApplication.VersionLong + " started, running instance is " + running); RssBanditApplication.StaticInit(appInstance); if (isFirstInstance) { // init to system default: RssBanditApplication.SharedCulture = CultureInfo.CurrentCulture; RssBanditApplication.SharedUICulture = CultureInfo.CurrentUICulture; if (appInstance.HandleCommandLineArgs(args)) { if (!string.IsNullOrEmpty(appInstance.CommandLineArgs.LocalCulture)) { try { RssBanditApplication.SharedUICulture = CultureInfo.CreateSpecificCulture(appInstance.CommandLineArgs.LocalCulture); RssBanditApplication.SharedCulture = RssBanditApplication.SharedUICulture; } catch (Exception ex) { appInstance.MessageError(String.Format( SR.ExceptionProcessCommandlineCulture, appInstance.CommandLineArgs.LocalCulture, ex.Message)); } } // take over customized cultures to current main thread: Thread.CurrentThread.CurrentCulture = RssBanditApplication.SharedCulture; Thread.CurrentThread.CurrentUICulture = RssBanditApplication.SharedUICulture; if (!appInstance.CommandLineArgs.StartInTaskbarNotificationAreaOnly && initialStartupState != FormWindowState.Minimized) { // no splash, if start option is tray only or minimized Splash.Show(SR.AppLoadStateLoading, RssBanditApplication.VersionLong); } if (appInstance.Init()) { // does also run the windows event loop: appInstance.StartMainGui(initialStartupState); Splash.Close(); } else { return(3); // init error } return(0); // OK } return(2); // CommandLine error } return(1); // other running instance }
protected void Application_Start(object sender, EventArgs e) { ApplicationActivator.UseEnvironment(EnvironmentName.Development).Startup(); RegisterRoutes(RouteTable.Routes); ServiceContainer.GetInstance <ICacheRepository>().SetVale("Sample", "ServiceBridge"); }