Example #1
0
        private static async Task MainAsync()
        {
            // SETUP DI services
            var services = new ServiceCollection();

            services.AddTransient <IHelloWorldAPI, HelloWorldAPIv1>();

            // include these 2 lines if database support is needed
            //services.AddTransient<IHelloWorldDbApi, HelloWorldDbApiV1>();
            services.AddTransient <IHelloWorldRepository, HelloWorldRepositoryFakeDb>();
            var provider = services.BuildServiceProvider();

            // Resolve needed services
            IHelloWorldAPI api = provider.GetService <IHelloWorldAPI>();
            // Include these 2 lines if database support is needed
            //IHelloWorldDbApi dbapi = provider.GetService<IHelloWorldDbApi>();
            IHelloWorldRepository repository = provider.GetService <IHelloWorldRepository>();

            try
            {
                Console.WriteLine(await api.GetMessageAsync());

                // include this line if database write is needed.
                await api.SaveMessageAsync(await api.GetMessageAsync());

                Console.WriteLine("Data saved to repository");
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing API methods.", ex);
            }
        }
        public HelloWorldController(IHelloWorldRepository repo)
        {
            _repo = repo;

            if (_repo.ListAll().Count() == 0)
            {
                _repo.Add();
            }
        }
Example #3
0
 public HelloController(IHelloWorldRepository iHelloWorldRepository)
 {
     _helloWorldRepository = iHelloWorldRepository;
 }
Example #4
0
 public HelloWorldService(IHelloWorldRepository helloWorldRepository)
 {
     _helloWorldRepository = helloWorldRepository;
 }
Example #5
0
 /// <summary>
 /// Constructor for the HelloWorldDbAPI
 /// </summary>
 /// <param name="helloWorldRepository">Injected IHelloWorldRepository object</param>
 public HelloWorldDbApiV1(IHelloWorldRepository helloWorldRepository)
 {
     repository = helloWorldRepository;
 }
Example #6
0
 public HelloWorldService(IHelloWorldRepository repository)
 {
     this._repository = repository;
 }
 public HelloWorldController(IHelloWorldRepository _helloworldRepo)
 {
     this.helloworldRepository = _helloworldRepo;
 }
 /// <summary>
 /// Constructor with dependency injection
 /// </summary>
 /// <param name="repo"></param>
 public HelloWorldService(IHelloWorldRepository repo)
 {
     _repo = repo;
 }
 public HelloWorldAPIv1(IHelloWorldRepository helloWorldRepository)
 {
     repository = helloWorldRepository;
 }
 public HelloWorldController(IHelloWorldRepository repo)
 {
     HelloWorldRepo = repo;
 }
 public DefaultPresenter(IHelloWorldRepository repository)
 {
     _repository = repository;
 }
Example #12
0
        // can break this out to a seperate project later so that it can be called from various applications
        // cmd prompt, web, android app, ect.

        public APIController(IHelloWorldRepository helloWorldRepository)
        {
            this.helloWorldRepository = helloWorldRepository;
        }
Example #13
0
 public HelloWorldTest()
 {
     _repository = new SimpleHelloWorldRepository();
     _controller = new APIController(_repository);
 }
Example #14
0
 public HelloWorldGetAllQueryHandler(IHelloWorldRepository helloWorldRepository)
 {
     this._helloWorldRepository = helloWorldRepository;
 }
 public HelloWorldController(IHelloWorldRepository helloWorldRepository)
 {
     _helloWorldRepository = helloWorldRepository;
 }