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(); } }
public HelloController(IHelloWorldRepository iHelloWorldRepository) { _helloWorldRepository = iHelloWorldRepository; }
public HelloWorldService(IHelloWorldRepository helloWorldRepository) { _helloWorldRepository = helloWorldRepository; }
/// <summary> /// Constructor for the HelloWorldDbAPI /// </summary> /// <param name="helloWorldRepository">Injected IHelloWorldRepository object</param> public HelloWorldDbApiV1(IHelloWorldRepository helloWorldRepository) { repository = helloWorldRepository; }
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; }
// 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; }
public HelloWorldTest() { _repository = new SimpleHelloWorldRepository(); _controller = new APIController(_repository); }
public HelloWorldGetAllQueryHandler(IHelloWorldRepository helloWorldRepository) { this._helloWorldRepository = helloWorldRepository; }
public HelloWorldController(IHelloWorldRepository helloWorldRepository) { _helloWorldRepository = helloWorldRepository; }