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();
        }
Example #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);
        }
Example #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;
 }
Example #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;
 }
Example #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();
        }
Example #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();
            }
        }
Example #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);
        }
Example #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;
 }
Example #11
0
        public SomethingController(IFooService fooService, IBooService booService, ILogger <SomethingController> logger)
        {
            Name = fooService.Repository.Session.Id.ToString("N");

            FooService = fooService;
            BooService = booService;

            Logger = logger;
        }
Example #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();
        }
Example #13
0
        public Service(IFooService fooService, IBarService barService)
        {
            if (fooService == null)
            {
                throw new ArgumentNullException("fooService");
            }

            this.fooService = fooService;
            this.barService = barService;
        }
Example #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");
        }
Example #16
0
        public Service(IFooService fooService, IBarService barService)
        {
            if (fooService == null)
            {
                throw new ArgumentNullException("fooService");
            }

            this.fooService = fooService;
            this.barService = barService;
        }
Example #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;
        }
Example #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}");
        }
Example #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>();
        }
Example #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);
        }
Example #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");
                }
            }
        }
Example #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");
                }
            }
        }
Example #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!");
        }
Example #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);
        }
Example #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;
        }
Example #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);
        }
Example #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;
 }
Example #34
0
 public absBaseRepo(IFooService fooService) => _fooService = fooService;
Example #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;
 }
Example #36
0
 public PersonBinder(IFooService service) {
     Service = service;
 }
Example #37
0
 public FooController(IFooService fooService)
 {
     this.fooService = fooService;
 }
 public DependencyController(IFooService fooService)
 {
     _fooService = fooService;
 }
Example #39
0
 public FooInterceptor(IFooService proxiedObject)
 {
     _proxiedObject = proxiedObject;
 }
Example #40
0
 public HomeController(IFooService fooService)
 {
     this._fooService = fooService;
 }
 public ServiceWithCtorArgs(string someString, IFooService fooService)
 {
     SomeString = someString;
     FooService = fooService;
 }
Example #42
0
		public MyModule(IFooService service) {
			Service = service;
		}
Example #43
0
 public GlobalFilter(IFooService service) {
     Service = service;
 }
Example #44
0
 public DemoApp(IFooService fooService)
 {
     _fooService = fooService;
 }
 public FooDecorator(IFooService fooService)
 {
     InnerService = fooService;
 }