Skip to content

Instantly share code, notes, and snippets.

@fabiocav
Created May 3, 2019 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiocav/996811f9351026686930f0456c74007f to your computer and use it in GitHub Desktop.
Save fabiocav/996811f9351026686930f0456c74007f to your computer and use it in GitHub Desktop.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
[assembly: FunctionsStartup(typeof(Microsoft.Azure.Functions.Samples.DependencyInjectionScopes.SampleStartup))]
namespace Microsoft.Azure.Functions.Samples.DependencyInjectionScopes
{
public class SampleStartup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
// Register MyServiceA as transient.
// A new instance will be returned every
// time a service request is made
builder.Services.AddTransient<MyServiceA>();
// Register MyServiceB as scoped.
// The same instance will be returned
// within the scope of a function invocation
builder.Services.AddScoped<MyServiceB>();
// Register ICommonIdProvider as scoped.
// The same instance will be returned
// within the scope of a function invocation
builder.Services.AddScoped<ICommonIdProvider, CommonIdProvider>();
// Register IGlobalIdProvider as singleton.
// A single instance will be created and reused
// with every service request
builder.Services.AddSingleton<IGlobalIdProvider, CommonIdProvider>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment