-
-
Save nemesv/f36b27826a401eec8f82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AutofacTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ContainerBuilder builder = new ContainerBuilder(); | |
builder.RegisterType<Logger>().As<ILogger>(); | |
builder.RegisterType<EchoService>(); | |
using (IContainer container = builder.Build()) | |
{ | |
Uri address = new Uri("http://localhost:8080/EchoService"); | |
ServiceHost host = new ServiceHost(typeof(EchoService), address); | |
var basicHttpBinding = new BasicHttpBinding(); | |
host.AddServiceEndpoint(typeof(IEchoService), basicHttpBinding, string.Empty); | |
host.AddServiceEndpoint(typeof(IEchoService2), basicHttpBinding, string.Empty); | |
host.AddDependencyInjectionBehavior<EchoService>(container); | |
host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = address }); | |
host.Open(); | |
Console.WriteLine("The host has been opened."); | |
Console.ReadLine(); | |
host.Close(); | |
Environment.Exit(0); | |
} | |
} | |
} | |
[ServiceContract] | |
public interface IEchoService | |
{ | |
[OperationContract] | |
string Test(); | |
} | |
[ServiceContract] | |
public interface IEchoService2 | |
{ | |
[OperationContract] | |
string Test2(); | |
} | |
public interface ILogger | |
{ | |
} | |
public class EchoService : IEchoService, IEchoService2 | |
{ | |
private readonly ILogger logger; | |
//just to see that Autofac inject the dependicies | |
public EchoService(ILogger logger) | |
{ | |
this.logger = logger; | |
} | |
public string Test() | |
{ | |
return "TEst1"; | |
} | |
public string Test2() | |
{ | |
return "TEst1"; | |
} | |
} | |
public class Logger : ILogger | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment