/// <summary> /// Initializes a new instance of the <see cref="RequisitionsController"/> class. /// </summary> /// <param name="serviceProvider"> /// The service provider. /// </param> public RequisitionsController(IServiceProvider serviceProvider) { Prevent.NullObject(serviceProvider, nameof(serviceProvider)); this.logger = serviceProvider.GetRequiredService <ILogger <RequisitionsController> >(); this.requisitionService = serviceProvider.GetRequiredService <IRequisitionService>(); }
/// <inheritdoc /> /// <exception cref="ArgumentNullException"> /// if widget is NULL. /// </exception> public async Task <Widget> CreateWidgetAsync( Widget widget, CancellationToken cancellationToken = default(CancellationToken)) { Prevent.NullObject(widget, nameof(widget)); // TODO: Validate widget before creating... return(await this.widgetRepository.AddAsync(widget, cancellationToken)); }
/// <summary> /// Changes the weight. /// </summary> /// <param name="weight"> /// The weight. /// </param> public void ChangeWeight(Weight weight) { Prevent.NullObject(weight, nameof(weight)); this.Weight = weight; this.IncrementVersion(); this.UpdateLastModifiedDate(); }
public async Task <IActionResult> CreateWidgetAsync(WidgetCreateRequest request) { Prevent.NullObject(request, nameof(request)); var newWidget = Widget.Create(request.Name, request.Description, new Weight(request.WeightInGrams)); var result = await this.widgetService.CreateWidgetAsync(newWidget); // TODO: Create widget GET Uri... return(this.Created(string.Empty, result)); }
/// <summary> /// Adds services required for injecting the IOptions{T} interface and /// registers all custom option types that should be injectable. /// </summary> /// <param name="services"> /// The services collection. /// </param> /// <param name="configuration"> /// The configuration root. /// </param> /// <returns> /// The <see cref="IServiceCollection"/>. /// </returns> /// TODO: What should we do with this? Can we make it more generic? Does it add value? Where should it live? public static IServiceCollection AddInjectableCustomOptions( this IServiceCollection services, IConfiguration configuration) { Prevent.NullObject(configuration, nameof(configuration)); // Add functionality to inject IOptions<T> services.AddOptions(); return(services); }
/// <summary> /// Registers all required DB contexts. /// </summary> /// <param name="services"> /// The services collection. /// </param> /// <param name="configuration"> /// The configuration. /// </param> /// <returns> /// The <see cref="IServiceCollection"/>. /// </returns> public static IServiceCollection AddDbContexts( this IServiceCollection services, IConfiguration configuration) { Prevent.NullObject(configuration, nameof(configuration)); // Add querying DB context services.AddDbContext <QueryingContext>( options => options.UseSqlServer(configuration.GetConnectionString("VMS")), ServiceLifetime.Transient); services.AddTransient <IQueryingContext, QueryingContext>(); // Add domain process event store DB context services.AddDbContext <ProcessEventStoreContext>( options => options.UseNpgsql(configuration.GetConnectionString("VMS.Requisitons")), ServiceLifetime.Transient); services.AddTransient <IProcessEventStoreContext, ProcessEventStoreContext>(); return(services); }
/// <summary> /// Initializes a new instance of the <see cref="WidgetService"/> class. /// </summary> /// <param name="widgetRepository"> /// The widget repository. /// </param> /// <exception cref="ArgumentNullException"> /// if widgetRepository is NULL. /// </exception> public WidgetService(IWidgetRepository widgetRepository) { Prevent.NullObject(widgetRepository, nameof(widgetRepository)); this.widgetRepository = widgetRepository; }
/// <summary> /// Initializes a new instance of the <see cref="RequisitionService"/> class. /// </summary> /// <param name="serviceProvider"> /// The service provider. /// </param> public RequisitionService(IServiceProvider serviceProvider) { Prevent.NullObject(serviceProvider, nameof(serviceProvider)); this.serviceProvider = serviceProvider; this.logger = serviceProvider.GetRequiredService <ILogger <RequisitionService> >(); }
/// <summary> /// Initializes a new instance of the <see cref="WidgetsController"/> class. /// </summary> /// <param name="widgetService"> /// The widget service. /// </param> public WidgetsController(IWidgetService widgetService) { Prevent.NullObject(widgetService, nameof(widgetService)); this.widgetService = widgetService; }