Skip to content

Instantly share code, notes, and snippets.

@Antaris
Created January 5, 2016 14:13
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 Antaris/9d1a0cad450bdf60a7c5 to your computer and use it in GitHub Desktop.
Save Antaris/9d1a0cad450bdf60a7c5 to your computer and use it in GitHub Desktop.
ASP.NET 5 Dependency Injection / Service Resolving in a Console App package
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace ConsoleApp1
{
public class Program
{
public static void Main(string[] args)
{
var collection = new ServiceCollection();
collection.AddTransient<IService, Service>();
var provider = collection.BuildServiceProvider();
var service = provider.GetService<IService>();
}
}
public interface IService
{
}
public class Service : IService
{
}
}
{
"version": "1.0.0-*",
"description": "ConsoleApp1 Console Application",
"authors": [ "Matthew Abbott" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final"
},
"commands": {
"ConsoleApp1": "ConsoleApp1"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment