Пример #1
0
        public async Task <AddPlatformPayload> AddPlatformAsync(
            AddPlatformInput input
            , [ScopedService] AppDbContext context
            , [Service] ITopicEventSender eventSender
            , CancellationToken cancellationToken
            )
        {
            var platform = input.toEntity();

            context.Platforms.Add(platform);
            await context.SaveChangesAsync(cancellationToken);

            await eventSender.SendAsync(nameof(Subscription.OnPlatformAdded), platform, cancellationToken);

            return(new AddPlatformPayload(platform));
        }
        [UseDbContext(typeof(AppDbContext))] //For multithreaded Db context.
        public async Task <AddPlatformPayload> AddPlatformAsync(AddPlatformInput input,
                                                                [ScopedService] AppDbContext context,
                                                                [Service] ITopicEventSender eventSender, //Use to send the event. Comes from Hotchocolate.Subscriptions
                                                                CancellationToken cancellationToken)     //Allows us to cancel async method calls if they're hanging for eg. It comes from System.Threading
        {
            var platform = new Platform
            {
                Name = input.Name
            };

            context.Platforms.Add(platform);
            await context.SaveChangesAsync(cancellationToken);

            await eventSender.SendAsync(nameof(Subscription.OnPlatformAdded), platform, cancellationToken);

            return(new AddPlatformPayload(platform));
        }
Пример #3
0
        public async Task <AddPlatformPayload> AddPlatformAsync(
            AddPlatformInput input,
            [ScopedService] AppDbContext context,
            [Service] ITopicEventSender eventSender, // used to subscribe to 'OnPlatformAdded'
            CancellationToken cancelletionToken)
        {
            Platform platform = new()
            {
                Name = input.Name
            };

            await context.Platforms.AddAsync(platform, cancelletionToken);

            await context.SaveChangesAsync(cancelletionToken);

            await eventSender.SendAsync(nameof(Subscription.OnPlatformAdded), platform, cancelletionToken);

            return(new AddPlatformPayload(platform));
        }