示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World! from console");

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", false, true)
                                .Build();


            using var serviceProvider = new ServiceCollection()
                                        .AddSingleton <IFooService, FooService>()
                                        .AddLogging(builder =>
            {
                builder.AddConfiguration(configuration.GetSection("Logging"));
                builder.AddConsole();
            })
                                        .BuildServiceProvider();


            ILogger <Program> logger = serviceProvider.GetService <ILogger <Program> >();
            //logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger<Program>(); // Factory first. This works too.

            IFooService fooService = serviceProvider.GetService <IFooService>();


            logger.LogInformation("1111logger information");
            logger.LogWarning("2222logger warning");

            fooService.DoWork();
        }
示例#2
0
        static async Task SimpleBenchmark(IFooService fooService)
        {
            var nCalls = 100 * 1000;

            var random = new Random();

            var tasksToWait = new ConcurrentBag<Task>();

            var sw = Stopwatch.StartNew();

            Parallel.For(0, nCalls, i =>
            {
                //gets a foo with id between 1 and 10, asynchronously
                tasksToWait.Add(
                    fooService.GetFooAsync(random.Next(1, 11)));
            });

            await Task.WhenAll(tasksToWait.ToArray());

            sw.Stop();

            Console.WriteLine("{0} calls completed in {1}", nCalls, sw.Elapsed);
            Console.WriteLine("Avg time per call: {0} ms", (double)sw.ElapsedMilliseconds / nCalls);
            Console.WriteLine("Requests per second: {0}", (double)nCalls / sw.Elapsed.TotalSeconds);
        }
示例#3
0
 private FooResponseModelBuilder(IFooService fooService)
 {
     _fooService     = fooService;
     _jobs           = new List <string>();
     _cities         = new List <string>();
     _selectedValues = new CityAndJob();
 }
 public ValuesController(ILogger <ValuesController> logger, AppConfig appConfig, IHostingEnvironment hostingEnvironment, IFooService fooService)
 {
     _hostingEnvironment = hostingEnvironment;
     _fooService         = fooService;
     _logger             = logger;
     _appConfig          = appConfig;
 }
示例#5
0
 public FooTrioConstructor(IFooService foo, IBarService bar, ICatService cat)
 {
     Foo    = foo;
     Bar    = bar;
     Cat    = cat;
     Option = "(Foo, Bar, Cat)";
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FooController"/> class.
 /// </summary>
 public FooController(
     IFooService fooService,
     IMapper mapper)
 {
     this._fooService = fooService;
     this._mapper     = mapper;
 }
示例#7
0
        static void Main(string[] args)
        {
            // dotnet add package Microsoft.Extensions.DependencyInjection

            IServiceCollection services = new ServiceCollection();

            ConfigureServices(services);

            //  services.AddScoped<IFooService, FooService>();
            //  services.AddScoped<IBooService, BooService>();
            //  services.AddLogging(configure => configure.AddConsole());

            using (var serviceProvider = services.BuildServiceProvider())
            {
                IFooService fooService = serviceProvider.GetService <IFooService>();

                string result = fooService.Get();

                System.Console.WriteLine(result);

                IBooService booService = serviceProvider.GetService <IBooService>();

                booService.DoWork();
            }

            System.Console.WriteLine("Press any key to exit.");

            Console.ReadKey();
        }
示例#8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World! from console");

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", false, true)
                                .Build();

            using var serviceProvider = new ServiceCollection()
                                        .AddSingleton <IFooService, FooService>()
                                        .AddLogging(builder =>
            {
                builder.AddConfiguration(configuration.GetSection("Logging"));
                builder.AddConsole();
            })
                                        .BuildServiceProvider();

            ILogger <Program> logger     = serviceProvider.GetService <ILogger <Program> >();
            IFooService       fooService = serviceProvider.GetService <IFooService>();


            logger.LogInformation("1111logger information");
            logger.LogWarning("2222logger warning");

            fooService.DoWork();

            using (var listener = new LoggerTraceListener(logger))
            {
                System.Diagnostics.Trace.Listeners.Add(listener);
                TraceSources.Instance.InitLoggerTraceListener(listener);

                TraceLover.DoSomething();
                TraceSourceLover.DoSomething();
            }
        }
示例#9
0
        static async Task SimpleBenchmark(IFooService fooService)
        {
            var nCalls = 100 * 1000;

            var random = new Random();

            var tasksToWait = new ConcurrentBag <Task>();

            var sw = Stopwatch.StartNew();

            Parallel.For(0, nCalls, i =>
            {
                //gets a foo with id between 1 and 10, asynchronously
                tasksToWait.Add(
                    fooService.GetFooAsync(random.Next(1, 11)));
            });

            await Task.WhenAll(tasksToWait.ToArray());

            sw.Stop();

            Console.WriteLine("{0} calls completed in {1}", nCalls, sw.Elapsed);
            Console.WriteLine("Avg time per call: {0} ms", (double)sw.ElapsedMilliseconds / nCalls);
            Console.WriteLine("Requests per second: {0}", (double)nCalls / sw.Elapsed.TotalSeconds);
        }
示例#10
0
 /// <summary>
 /// Creates new instance of <see cref="FooController"/>.
 /// </summary>
 /// <param name="connectionStrings">
 /// Instance of <see cref="IOptionsSnapshot{ConnectionStrings}"/> object that contains connection string.
 /// More information: https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.options.ioptionssnapshot-1?view=aspnetcore-2.1
 /// TODO: https://www.strathweb.com/2016/09/strongly-typed-configuration-in-asp-net-core-without-ioptionst/
 /// </param>
 /// <param name="service">Instance of <see cref="IFooService"/></param>
 /// <param name="logger"></param>
 public FooController(IOptionsSnapshot <ConnectionStrings> connectionStrings, IFooService service, ILogger <FooController> logger, PlacesDBContext placesDBContext)
 {
     _connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings));
     _service           = service ?? throw new ArgumentNullException(nameof(service));
     _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
     _placesDB          = placesDBContext;
 }
示例#11
0
        public SomethingController(IFooService fooService, IBooService booService, ILogger <SomethingController> logger)
        {
            Name = fooService.Repository.Session.Id.ToString("N");

            FooService = fooService;
            BooService = booService;

            Logger = logger;
        }
示例#12
0
        public BarModelValidator(IFooService fooService)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(x => x.Name).NotNull()
            .Must(x => x == fooService.GetBar(2).ToString())
            .WithMessage(x => $"{nameof(x.Name)} 要等於 {fooService.GetBar(2).ToString()}");
            RuleFor(x => x.Email).NotNull().EmailAddress();
        }
示例#13
0
        public Service(IFooService fooService, IBarService barService)
        {
            if (fooService == null)
            {
                throw new ArgumentNullException("fooService");
            }

            this.fooService = fooService;
            this.barService = barService;
        }
示例#14
0
        public HomeController(IFooService fooService, [ConfigDependency] String mySetting)
        {
            if (fooService == null)
                throw new ArgumentNullException("fooService");

            if (String.IsNullOrEmpty(mySetting))
                throw new ArgumentNullException("mySetting");

            _fooService = fooService;
        }
        public FooController()
        {
            var factory = new ServiceProxyFactory(c => new FabricTransportServiceRemotingClientFactory(
                                                      serializationProvider: new ServiceRemotingJsonSerializationProvider()));

            _service = factory.CreateServiceProxy <IFooService>(new Uri("fabric:/SF.Example/Remoting"),
                                                                new ServicePartitionKey(),
                                                                TargetReplicaSelector.Default,
                                                                "FooListener");
        }
示例#16
0
        public Service(IFooService fooService, IBarService barService)
        {
            if (fooService == null)
            {
                throw new ArgumentNullException("fooService");
            }

            this.fooService = fooService;
            this.barService = barService;
        }
示例#17
0
        protected void Setup()
        {
            StatsdMock = new Mock <IVeStatsDClient>();
            Container  = new Container();

            Container.RegisterSingleton <IVeStatsDClient>(StatsdMock.Object);
            Container.RegisterSingleton <IFooService, FooService>();
            Container.InterceptWith <T1>(type => type == typeof(IFooService));

            Service = Container.GetInstance <IFooService>();
        }
        public FooController(
            IFooService fooService,
            IOptions <SampleConfig> sampleConfig,
            ILogger <FooController> logger)
        {
            _fooService = fooService;
            _logger     = logger;

            // Example: Use IOptions pattern
            _sampleConfig = sampleConfig.Value;
        }
示例#19
0
        protected void Setup()
        {
            StatsdMock = new Mock <IVeStatsDClient>();
            Container  = new WindsorContainer();

            Container.Register(Component.For <IVeStatsDClient>().Instance(StatsdMock.Object));
            Container.Register(Component.For <T1>());
            Container.Register(Component.For <IFooService>().ImplementedBy <FooService>().Interceptors <T1>());

            Service = Container.Resolve <IFooService>();
        }
        public MyChildActor(IFooService fooService)
        {
            _fooService = fooService;

            Receive <BeginChildMessage>(message =>
            {
                var x = _fooService.ReturnValue(12);
                Console.WriteLine($"IFooService.ReturnValue(12) gave result {x}");

                Sender.Tell(new ChildSucceededMessage("MyChildActor"));
            });
        }
        public static async Task RunAsync()
        {
            ILogger <Program> logger = Services.GetService <ILogger <Program> >();

            logger.LogInformation("App is running ...");

            IFooService fooService = Services.GetService <IFooService>();

            var foo = await fooService.GetFooAsync();

            System.Console.WriteLine($"FooService returned: {foo}");
        }
示例#22
0
        public void DoWork_when_IFooService_Update_returns_false_returns_false_MockVersion()
        {
            var         mock    = new Mock <IFooService>();
            IFooService service = mock.Object;

            using (var worker = new WorkerConstructorInjection(service))
            {
                var result = worker.DoWork(new FooDto());

                Assert.False(result);
            }
        }
        protected void Setup()
        {
            StatsdMock = new Mock <IVeStatsDClient>();
            Container  = new UnityContainer();

            Container.RegisterInstance(StatsdMock.Object);
            Container.AddNewExtension <Interception>();
            Container.RegisterType <IFooService, FooService>(
                new Interceptor <InterfaceInterceptor>(),
                new InterceptionBehavior <T1>()
                );

            Service = Container.Resolve <IFooService>();
        }
示例#24
0
        public frmMain(ILogger <frmMain> logger, IFooService fooService, IServiceProvider serviceProvider, IOptions <AppSettings> options)
        {
            InitializeComponent();

            this.logger = logger;
            logger.LogInformation("Creating MainForm...");

            this.fooService      = fooService;
            this.serviceProvider = serviceProvider;

            var settings = options.Value;

            logger.LogDebug("Setting1: {Setting1}", settings.Setting1);
            logger.LogDebug("Setting2: {Setting2}", settings.Setting2);
        }
示例#25
0
        static void GetFooAndUpdate(IFooService fooService)
        {
            var foo = fooService.GetFoo(5);

            if (foo.Name == "Foo 5")
            {
                foo.Name = "Foo 1337";
                fooService.UpdateFoo(foo);

                var l33t = fooService.GetFoo(5);
                if (l33t.Name == "Foo 1337")
                {
                    Console.WriteLine("Successfully updated Foo 5 name to Foo 1337");
                }
            }
        }
示例#26
0
        static void GetFooAndUpdate(IFooService fooService)
        {
            var foo = fooService.GetFoo(5);

            if (foo.Name == "Foo 5")
            {
                foo.Name = "Foo 1337";
                fooService.UpdateFoo(foo);

                var l33t = fooService.GetFoo(5);
                if (l33t.Name == "Foo 1337")
                {
                    Console.WriteLine("Successfully updated Foo 5 name to Foo 1337");
                }
            }
        }
示例#27
0
        private static void Main()
        {
            // Create service collection
            IServiceCollection serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);
            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            ILogger logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger("Program");

            logger.LogInformation("Example log message");

            IFooService fooService = serviceProvider.GetService <IFooService>();

            fooService.DoThing(1);
            logger.LogInformation("Hello World!");
        }
示例#28
0
        public void Run()
        {
            var serviceWithNameA = _pluginFactory.GetServiceByName("NameA");

            Console.WriteLine("Got: " + serviceWithNameA.PluginName());
            var serviceWithNameB = _pluginFactory.GetServiceByName("NameIsB");

            Console.WriteLine("Got: " + serviceWithNameB.PluginName());

            Console.WriteLine("Resolve a foo class at runtime...");
            IFooService foo = _fooFactory.Create();

            foo.DoSomething();

            Console.WriteLine("Press any key.");
            Console.ReadLine();
        }
        public MainWindow(ILogger <MainWindow> logger, IOptions <AppSettings> options,
                          IFooService fooService, IServiceProvider serviceProvider)
        {
            InitializeComponent();

            this.logger          = logger;
            appSettings          = options.Value;
            this.serviceProvider = serviceProvider;

            logger.LogInformation("Loading MainWindow...");

            logger.LogDebug("Setting1: {Setting1}", appSettings.Setting1);
            logger.LogDebug("Setting2: {Setting2}", appSettings.Setting2);

            var value = fooService.GetFoo();

            logger.LogDebug("Service Value: {Value}", value);
        }
示例#30
0
        public App(IStringWriter writer, IFooService fooService, IBarService barService)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (fooService == null)
            {
                throw new ArgumentNullException(nameof(fooService));
            }
            if (barService == null)
            {
                throw new ArgumentNullException(nameof(barService));
            }

            _writer     = writer;
            _fooService = fooService;
            _barService = barService;
        }
示例#31
0
        public MainPageViewModel(INavigationService navigationService, IDialogService dialogService, IPageDialogService pageDialogService, IFooService fooService)
            : base(navigationService)
        {
            _pageDialog = pageDialogService;
            _fooService = fooService;
            Title       = "Main Page";
            BgColor     = Color.Cornsilk;
            Hello       = _fooService.SayHello();
            ShowDialog  = new DelegateCommand(async() =>
            {
                dialogService.ShowDialog("DialogView", CloseDialogCallback);
            });

            ShowAlert = new DelegateCommand(ShowSimpleAlert);

            //modal: useModalNavigation: true
            NavigateToSecondPage = new DelegateCommand(async() =>
                                                       await NavigationService.NavigateAsync("SecondPage"));

            ChangeColor = new DelegateCommand(() => BgColor = Color.Red);
        }
示例#32
0
        /// <summary>
        /// Executes the application.
        /// </summary>
        static public void Main(string[] args)
        {
            //setup our Service configuration
            IServiceProvider serviceProvider = ServiceCofigurator.GetServiceProvider();

            var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <Program>();

            logger.LogInformation("Starting application");

            //do the actual work here
            using (IFooService foo = serviceProvider.GetService <IFooService>())
            {
                logger.LogInformation("FooService first run");
                foo.DoFileService();
                foo.DoRegexService();
            }

            //do the actual work here
            using (IFooService foo = serviceProvider.GetService <IFooService>())
            {
                logger.LogInformation("FooService second run");
                foo.DoFileService();
                foo.DoRegexService();
                foo.DoTupleService();
            }

            //do the actual work here
            using (ICarService carService = serviceProvider.GetService <ICarService>())
            {
                carService.CreateCarport();
                carService.SellCar(1, "Mike Coley");

                DataSet ds = carService.ListCars();
                logger.LogInformation("DataSet {0}", ds.GetXml());
            }

            logger.LogInformation("Finishing application");
        }
 public ServiceWithCtorArgs(IFooService fooService)
 {
     FooService = fooService;
 }
示例#34
0
 public absBaseRepo(IFooService fooService) => _fooService = fooService;
示例#35
0
 public FooB(IFooService fooService)
 {
     Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} #{1} {2}", this.GetType().Name, this.GetHashCode(), ".ctor, got fooService #" + fooService.GetHashCode()));
     this.fooService = fooService;
 }
示例#36
0
 public PersonBinder(IFooService service) {
     Service = service;
 }
示例#37
0
 public FooController(IFooService fooService)
 {
     this.fooService = fooService;
 }
 public DependencyController(IFooService fooService)
 {
     _fooService = fooService;
 }
示例#39
0
 public FooInterceptor(IFooService proxiedObject)
 {
     _proxiedObject = proxiedObject;
 }
示例#40
0
 public HomeController(IFooService fooService)
 {
     this._fooService = fooService;
 }
 public ServiceWithCtorArgs(string someString, IFooService fooService)
 {
     SomeString = someString;
     FooService = fooService;
 }
示例#42
0
		public MyModule(IFooService service) {
			Service = service;
		}
示例#43
0
 public GlobalFilter(IFooService service) {
     Service = service;
 }
示例#44
0
 public DemoApp(IFooService fooService)
 {
     _fooService = fooService;
 }
示例#45
0
 public FooDecorator(IFooService fooService)
 {
     InnerService = fooService;
 }