Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Software Development is my passion!

Carlos dos Santos carloscds

💭
Software Development is my passion!
View GitHub Profile
View InjecaoEF_Contexto
using InjecaoDependenciaDiretaEF.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaDiretaEF.Data
{
public class AplicacaoContext : DbContext
View InjecaoEF_Cliente
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaDiretaEF.Models
{
public class Cliente
{
public int Id { get; set; }
View InjecaoSingleton.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSingleton<IServico, Servico>();
services.AddSingleton<ExecutaServico, ExecutaServico>();
}
View InjecaoScoped.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddScoped<IServico, Servico>();
services.AddScoped<ExecutaServico, ExecutaServico>();
}
View InjecaoTransient.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddTransient<IServico, Servico>();
services.AddTransient<ExecutaServico, ExecutaServico>();
}
View HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace InjecaoDependenciaASPNETCore.Controllers
{
[ApiController]
View ExecutaServico.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaASPNETCore
{
public class ExecutaServico
{
private readonly IServico _servico;
View Servico.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaASPNETCore
{
public class Servico : IServico
{
private int contador;
View IServico.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaASPNETCore
{
public interface IServico
{
string RetornaValor();
View DI_ExecutaNInject.cs
using System;
using Ninject;
namespace ExemploNInject
{
class Program
{
static void Main(string[] args)
{
Ninject.IKernel inject = new StandardKernel();