ASP.NET 5 dependency injection, inject with parameters -
i'm using vnext implementation of di. how pass parameters constructor? example, have class:
public class rediscacheprovider : icacheprovider { private readonly string _connectionstring; public rediscacheprovider(string connectionstring) { _connectionstring = connectionstring; } //interface methods implementation... } and service register:
services.addsingleton<icacheprovider, rediscacheprovider>(); how pass parameter constructor of rediscacheprovider class? example autofac:
builder.registertype<rediscacheprovider>() .as<icacheprovider>() .withparameter("connectionstring", "myprettylocalhost:6379");
you can either provide delegate manually instantiate cache provider or directly provide instance:
services.addsingleton<icacheprovider>(provider => new rediscacheprovider("myprettylocalhost:6379")); services.addinstance<icacheprovider>(new rediscacheprovider("myprettylocalhost:6379"));
Comments
Post a Comment