public async Task StartAsync(CancellationToken cancellationToken)
    {
        using (var application = await AbpApplicationFactory.CreateAsync <MyProjectNameConsoleApiClientModule>(options =>
        {
            options.Services.ReplaceConfiguration(_configuration);
            options.UseAutofac();
        }))
        {
            await application.InitializeAsync();

            var demo = application.ServiceProvider.GetRequiredService <ClientDemoService>();
            await demo.RunAsync();

            await application.ShutdownAsync();
        }
    }
Esempio n. 2
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <AppModule>())
            {
                Console.WriteLine("调用Initialize前");
                application.Initialize();//初始化
                Console.WriteLine("调用Initialize后");

                var helloWorldService =
                    application.ServiceProvider.GetService(typeof(HelloWorldService)) as HelloWorldService;
                helloWorldService.Hello();
                Console.WriteLine("调用Shutdown前");
                application.Shutdown();
                Console.WriteLine("调用Shutdown后");
            }
            Console.WriteLine("Hello World!");
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create <LoanSampleMigratorModule>(options => {
                options.UseAutofac();
                options.Services.AddLogging(c => c.AddSerilog());
            }))
            {
                application.Initialize();

                await application
                .ServiceProvider
                .GetRequiredService <CustomerStoreDbMigrationService>()
                .MigrateAsync();

                application.Shutdown();
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var application = AbpApplicationFactory.Create <MainModule>(options =>
            {
                options.UseAutofac();
            });

            application.Initialize();

            var hello = application.ServiceProvider.GetRequiredService <IHelloService>();

            hello.Greeting();

            var aloha = application.ServiceProvider.GetRequiredService <IAlohaService>();

            aloha.Greeting();
        }
    public async Task StartAsync(CancellationToken cancellationToken)
    {
        using (var application = AbpApplicationFactory.Create <ConsoleAppConsoleAppModule>(options =>
        {
            options.UseAutofac();
            options.Services.AddLogging(c => c.AddSerilog());
        }))
        {
            application.Initialize();

            var blobService = application.ServiceProvider.GetService <BlobService>();

            await blobService.SaveFile("Test File 2", "Test Content 2");

            application.Shutdown();
        }
    }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            using (var application = AbpApplicationFactory.Create <GrpcDemoConsoleApiClientModule>())
            {
                application.Initialize();

                var demo = application.ServiceProvider.GetRequiredService <ClientDemoService>();
                await demo.RunAsync();

                var grpcDemo = application.ServiceProvider.GetRequiredService <GrpcClientDemoService>();
                await grpcDemo.RunAsync();

                application.Shutdown();
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            using (var application =
                       AbpApplicationFactory.Create <AppModule>(opt => opt.UseAutofac()))
            {
                application.Initialize();

                using (var scope = application.ServiceProvider.CreateScope())
                {
                    var helloWorldService = scope.ServiceProvider.GetService <HelloWorldService>();
                    helloWorldService.SayHello();
                }

                Console.WriteLine("Press ENTER to stop application...");
                Console.ReadLine();
            }
        }
Esempio n. 8
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _abpApplication = await AbpApplicationFactory.CreateAsync <EasyStoreConsoleAppAppModule>(options =>
            {
                options.Services.ReplaceConfiguration(_configuration);
                options.Services.AddSingleton(_hostEnvironment);

                options.UseAutofac();
                options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog());
            });

            await _abpApplication.InitializeAsync();

            var helloWorldService = _abpApplication.ServiceProvider.GetRequiredService <HelloWorldService>();

            await helloWorldService.SayHelloAsync();
        }
Esempio n. 9
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     using (var application = AbpApplicationFactory.Create <FacCigoWinUIModule>(options =>
     {
         options.UseAutofac();//Autofac integration
     }))
     {
         application.Initialize();
         Application.SetHighDpiMode(HighDpiMode.SystemAware);
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         var mainForm = application.ServiceProvider.GetService <MainForm>();
         Application.Run(mainForm);
         application.Shutdown();
     }
     return(Task.CompletedTask);
 }
Esempio n. 10
0
        static void Main(string[] args)
        {
            ConfigureLogging();

            using (var application = AbpApplicationFactory.Create <MysqlDemoDbMigratorModule>(options =>
            {
                options.UseAutofac();
                options.Services.AddLogging(c => c.AddSerilog());
            }))
            {
                application.Initialize();
                string start = string.Empty;
                Console.WriteLine("Input start to start migration database");
                while (true)
                {
                    if (start == "start")
                    {
                        try
                        {
                            AsyncHelper.RunSync(
                                () => application
                                .ServiceProvider
                                .GetRequiredService <MysqlDemoDbMigrationService>()
                                .MigrateAsync()
                                );
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        Console.WriteLine("End the migration");
                        Console.WriteLine("Input start to start migration database");
                    }

                    start = Console.ReadLine();
                    if (start == "exit")
                    {
                        break;
                    }
                }


                application.Shutdown();
            }
        }
Esempio n. 11
0
        private static void Run(Options o)
        {
            string saveAsPath;

            if (!File.Exists(o.ContractDllPath))
            {
                Console.WriteLine($"error: Contract DLL cannot be found in specified path {o.ContractDllPath}");
                return;
            }

            if (o.Overwrite)
            {
                saveAsPath = o.ContractDllPath;
                Console.WriteLine($"[CONTRACT-PATCHER] Overwriting {saveAsPath}");
            }
            else
            {
                saveAsPath = o.ContractDllPath + ".patched";
                Console.WriteLine($"[CONTRACT-PATCHER] Saving as {saveAsPath}");
            }

            using var application = AbpApplicationFactory.Create <ContractDeployerModule>();
            application.Initialize();
            var contractPatcher = application.ServiceProvider.GetRequiredService <IContractPatcher>();
            var patchedCode     = contractPatcher.Patch(File.ReadAllBytes(o.ContractDllPath), o.IsSystemContract);

            if (!o.SkipAudit)
            {
                try
                {
                    var auditor = application.ServiceProvider.GetRequiredService <IContractAuditor>();
                    auditor.Audit(patchedCode, null, o.IsSystemContract);
                }
                catch (CSharpCodeCheckException ex)
                {
                    foreach (var finding in ex.Findings)
                    {
                        // Print error in parsable format so that it can be shown in IDE
                        Console.WriteLine($"error: {finding.ToString()}");
                    }
                }
            }

            File.WriteAllBytes(saveAsPath, patchedCode);
        }
Esempio n. 12
0
        private static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <App1Module>(options =>
            {
                options.UseAutofac();
            }))
            {
                application.Initialize();

                var messagingService = application
                                       .ServiceProvider
                                       .GetRequiredService <App1MessagingService>();

                messagingService.Run();

                application.Shutdown();
            }
        }
Esempio n. 13
0
        static async Task Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <PublisherModule>(options =>
            {
                options.UseAutofac();
            }))
            {
                application.Initialize();

                var messagingService = application
                                       .ServiceProvider
                                       .GetRequiredService <MessagingService>();

                await messagingService.RunAsync();

                application.Shutdown();
            }
        }
Esempio n. 14
0
    public void Should_Use_Default_ServiceScopeFactory_By_Default()
    {
        using (var application = AbpApplicationFactory.Create <IndependentEmptyModule>())
        {
            application.Services.AddType(typeof(MyService));

            application.Initialize();

            var serviceScopeFactory = application.ServiceProvider.GetRequiredService <IHybridServiceScopeFactory>();

            using (var scope = serviceScopeFactory.CreateScope())
            {
                scope.ServiceProvider.GetRequiredService <MyService>();
            }

            MyService.DisposeCount.ShouldBe(1);
        }
    }
Esempio n. 15
0
        static void Main(string[] args)
        {
            ConfigureLogging();

            using (var application = AbpApplicationFactory.Create <BookStoreDbMigratorModule>(options =>
            {
                options.UseAutofac();
                options.Services.AddLogging(c => c.AddSerilog());
            }))
            {
                application.Initialize();

                AsyncHelper.RunSync(() => application.ServiceProvider.GetRequiredService <BookStoreDbMigrationService>()
                                    .MigrateAsync());

                application.Shutdown();
            }
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <AppModule>(options =>
            {
                options.UseAutofac(); //Autofac integration
            }))
            {
                application.Initialize();

                //Resolve a service and use it
                var helloWorldService =
                    application.ServiceProvider.GetService <HelloWorldService>();
                helloWorldService.SayHello();

                Console.WriteLine("Press ENTER to stop application...");
                Console.ReadLine();
            }
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create <ConsoleClientDemoModule>(options =>
            {
                options.Services.AddLogging(loggingBuilder =>
                {
                    loggingBuilder.AddSerilog(dispose: true);
                });
            }))
            {
                application.Initialize();

                var demo = application.ServiceProvider.GetRequiredService <ClientDemoService>();
                await demo.RunAsync();

                application.Shutdown();
            }
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            var application = AbpApplicationFactory.Create <MainModule>();

            application.Initialize();

            var singletonSvc = application.ServiceProvider.GetRequiredService <MyService>();

            Console.WriteLine("output in de");
            CultureInfo.CurrentUICulture = new CultureInfo("de");
            singletonSvc.Greeting();
            Console.WriteLine("-----------------------------");

            Console.WriteLine("output in en");
            CultureInfo.CurrentUICulture = new CultureInfo("en");
            singletonSvc.Greeting();
            Console.WriteLine("-----------------------------");
        }
Esempio n. 19
0
        private static void RunDemo()
        {
            using (var application = AbpApplicationFactory.Create <AbpDeskConsoleDemoModule>(options =>
            {
                options.UseAutofac();
                AddPlugIns(options);
            }))
            {
                application.Initialize();

                RunListers(application);

                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();

                application.Shutdown();
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <AppModule>(options =>
            {
                options.UseAutofac();
            }))
            {
                application.Initialize();

                application.ServiceProvider.GetRequiredService <IDistributedEventBus>(); //TODO: Workaround, remove after ABP v0.15

                Console.WriteLine("************* STARTED the SUBSCRIBER *************");
                Console.WriteLine("Press ENTER to stop application...");
                Console.ReadLine();

                application.Shutdown();
            }
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <WorkerConcurrencyAElfModule>(options =>
            {
                options.UseAutofac();
            }))
            {
                application.Initialize();

                Logger = application.ServiceProvider.GetRequiredService <ILogger <Program> >();

                var service = application.ServiceProvider.GetRequiredService <ActorEnvironment>();
                service.InitWorkActorSystem();
                Console.WriteLine("Press Control + C to terminate.");
                Console.CancelKeyPress += async(sender, eventArgs) => { await service.StopAsync(); };
                service.TerminationHandle.Wait();
            }
        }
Esempio n. 22
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create <AppModule>(options =>
            {
                options.UseAutofac(); //Autofac integration
            }))
            {
                application.Initialize();

                //Resolve a service and use it
                var helloWorldService = application.ServiceProvider.GetService <HelloWorldService>();
                helloWorldService.SayHello();

                application.Shutdown();
            }

            return(Task.CompletedTask);
        }
Esempio n. 23
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <ConsoleApiClientModule>(options =>
            {
                options.UseAutofac();
            }))
            {
                application.Initialize();

                using (var scope = application.ServiceProvider.CreateScope())
                {
                    var demoService = scope.ServiceProvider.GetRequiredService <ApiClientDemoService>();
                    AsyncHelper.RunSync(() => demoService.RunAsync());
                }

                Console.WriteLine("Press ENTER to stop application...");
                Console.ReadLine();
            }
        }
Esempio n. 24
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create <ShopDbMigratorModule>(options =>
            {
                options.UseAutofac();
            }))
            {
                application.Initialize();

                await application
                .ServiceProvider
                .GetRequiredService <ShopDbMigrationService>()
                .MigrateAsync();

                application.Shutdown();

                _hostApplicationLifetime.StopApplication();
            }
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <MyConsoleModule>(options =>
            {
            }))
            {
                application.Initialize();

                Console.WriteLine("ABP initialized... Press ENTER to exit!");

                var writers = application.ServiceProvider.GetServices <IMessageWriter>();
                foreach (var writer in writers)
                {
                    writer.Write();
                }

                Console.ReadLine();
            }
        }
Esempio n. 26
0
    public async Task Should_Initialize_PlugIn_Async()
    {
        using (var application = await AbpApplicationFactory.CreateAsync <IndependentEmptyModule>(options =>
        {
            options.PlugInSources.AddTypes(typeof(IndependentEmptyPlugInModule));
        }))
        {
            //Assert
            var plugInModule = application.Services.GetSingletonInstance <IndependentEmptyPlugInModule>();

            plugInModule.PreConfigureServicesAsyncIsCalled.ShouldBeTrue();
            plugInModule.PreConfigureServicesIsCalled.ShouldBeTrue();

            plugInModule.ConfigureServicesAsyncIsCalled.ShouldBeTrue();
            plugInModule.ConfigureServicesIsCalled.ShouldBeTrue();

            plugInModule.PostConfigureServicesAsyncIsCalled.ShouldBeTrue();
            plugInModule.PostConfigureServicesIsCalled.ShouldBeTrue();

            //Act
            await application.InitializeAsync();

            //Assert
            application.ServiceProvider.GetRequiredService <IndependentEmptyPlugInModule>().ShouldBeSameAs(plugInModule);

            plugInModule.OnPreApplicationInitializationAsyncIsCalled.ShouldBeTrue();
            plugInModule.OnPreApplicationInitializationIsCalled.ShouldBeTrue();

            plugInModule.OnApplicationInitializeAsyncIsCalled.ShouldBeTrue();
            plugInModule.OnApplicationInitializeIsCalled.ShouldBeTrue();

            plugInModule.OnPostApplicationInitializationAsyncIsCalled.ShouldBeTrue();
            plugInModule.OnPostApplicationInitializationIsCalled.ShouldBeTrue();

            //Act
            await application.ShutdownAsync();

            //Assert
            plugInModule.OnApplicationShutdownAsyncIsCalled.ShouldBeTrue();
            plugInModule.OnApplicationShutdownIsCalled.ShouldBeTrue();
        }
    }
    public void TransientCachedServiceProvider_Should_Cache_Services()
    {
        void TestResolvingServices(IServiceScope scope)
        {
            var transientCachedServiceProvider1 = scope.ServiceProvider.GetRequiredService <ITransientCachedServiceProvider>();

            var transientTestService1_1 = transientCachedServiceProvider1.GetRequiredService <TransientTestService>();
            var transientTestService1_2 = transientCachedServiceProvider1.GetRequiredService <TransientTestService>();

            transientTestService1_1.ShouldBeSameAs(transientTestService1_2);

            var transientCachedServiceProvider2 = scope.ServiceProvider.GetRequiredService <ITransientCachedServiceProvider>();

            transientCachedServiceProvider1.ShouldNotBeSameAs(transientCachedServiceProvider2);

            var transientTestService2_1 = transientCachedServiceProvider2.GetRequiredService <TransientTestService>();
            var transientTestService2_2 = transientCachedServiceProvider2.GetRequiredService <TransientTestService>();

            transientTestService2_1.ShouldBeSameAs(transientTestService2_2);

            transientTestService1_1.ShouldNotBeSameAs(transientTestService2_1);

            var transientCachedServiceProvider1_1 = transientCachedServiceProvider1.GetRequiredService <IServiceProvider>().GetRequiredService <ITransientCachedServiceProvider>();
            var transientCachedServiceProvider1_2 = transientCachedServiceProvider1.GetRequiredService <IServiceProvider>().GetRequiredService <ITransientCachedServiceProvider>();

            transientCachedServiceProvider1_1.ShouldNotBeSameAs(transientCachedServiceProvider1);
            transientCachedServiceProvider1_2.ShouldNotBeSameAs(transientCachedServiceProvider1);
            transientCachedServiceProvider1_1.ShouldNotBeSameAs(transientCachedServiceProvider1_2);
        }

        using (var application = AbpApplicationFactory.Create <TestModule>())
        {
            application.Initialize();

            using (var scope1 = application.ServiceProvider.CreateScope())
            {
                TestResolvingServices(scope1);
                var testCounter = scope1.ServiceProvider.GetRequiredService <ITestCounter>();
                testCounter.GetValue(nameof(TransientTestService)).ShouldBe(2);
            }
        }
    }
Esempio n. 28
0
        static void Main(string[] args)
        {
            using (var application = AbpApplicationFactory.Create <AdminDbMigratorModule>(options =>
            {
                options.UseAutofac();
                // options
            }))
            {
                application.Initialize();

                AsyncHelper.RunSync(
                    () => application
                    .ServiceProvider
                    .GetRequiredService <AdminDbMigrationService>()
                    .MigrateAsync()
                    );

                application.Shutdown();
            }
        }
Esempio n. 29
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create <DemoConsoleAppModule>(options =>
            {
                options.UseAutofac(); //Autofac integration
                options.Services.AddLogging(c => c.AddSerilog());
            }))
            {
                application.Initialize();

                var backgroundWorkerManager = application.ServiceProvider.GetService <IBackgroundWorkerManager>();
                var worker = application.ServiceProvider.GetService <SendEmailWorker>();
                backgroundWorkerManager.Add(worker);

                Console.ReadKey();
                application.Shutdown();
            }

            return(Task.CompletedTask);
        }
Esempio n. 30
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create <QuestionnaireInvestigationDbMigratorModule>(options =>
            {
                options.UseAutofac();
                options.Services.AddLogging(c => c.AddSerilog());
            }))
            {
                application.Initialize();

                await application
                .ServiceProvider
                .GetRequiredService <QuestionnaireInvestigationDbMigrationService>()
                .MigrateAsync();

                application.Shutdown();

                _hostApplicationLifetime.StopApplication();
            }
        }