Skip to content

Instantly share code, notes, and snippets.

View carloscds's full-sized avatar
💭
Looking forward, everyday!

Carlos dos Santos carloscds

💭
Looking forward, everyday!
View GitHub Profile
using System;
using System.Data;
using Microsoft.Data.SqlClient;
namespace BasicDI
{
class Program
{
static void Main(string[] args)
{
using System;
namespace ExemploNInject
{
public interface IServico
{
public void Executa();
}
public class MeuServico : IServico
using System;
namespace ExemploNInject
{
public class ExecutaDI
{
private IServico _servico;
public ExecutaDI(IServico servico)
{
_servico = servico;
using System;
using Ninject;
namespace ExemploNInject
{
class Program
{
static void Main(string[] args)
{
Ninject.IKernel inject = new StandardKernel();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaASPNETCore
{
public interface IServico
{
string RetornaValor();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaASPNETCore
{
public class Servico : IServico
{
private int contador;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace InjecaoDependenciaASPNETCore
{
public class ExecutaServico
{
private readonly IServico _servico;
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]
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddTransient<IServico, Servico>();
services.AddTransient<ExecutaServico, ExecutaServico>();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddScoped<IServico, Servico>();
services.AddScoped<ExecutaServico, ExecutaServico>();
}