arom...@gmail.com
unread,Feb 18, 2015, 2:17:49 PM2/18/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to aut...@googlegroups.com
I can't get the UrlHelper to work in the webapi (owin).
In Startup, I'm calling: AutofacConfig.RegisterDependencies(app);
public static void RegisterDependencies(IAppBuilder app)
{
var builder = new ContainerBuilder();
var svcAssembly = typeof(HomeService).Assembly;
var repoAssembly = typeof(RepositoryBase).Assembly;
var apiAssembly = Assembly.GetExecutingAssembly();
var config = GlobalConfiguration.Configuration;
builder.RegisterHttpRequestMessage(config);
builder.RegisterType(typeof(ReportToMeDataContext))
.AsSelf();
builder.Register(c => new LinkFactory(c.Resolve<HttpRequestMessage>())).InstancePerRequest();
builder
.RegisterType(typeof(ReportToMeDataContext))
.AsSelf()
.InstancePerLifetimeScope();
builder
.RegisterGeneric(typeof(ReportToMe.Data.Repository<>))
.As(typeof(IRepository<>));
builder
.RegisterType(typeof(UnitOfWork))
.As(typeof(IUnitOfWork));
builder.RegisterAssemblyTypes(svcAssembly)
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(repoAssembly)
.Where(t => t.Name.EndsWith("Repository"))
.AsImplementedInterfaces();
builder.RegisterApiControllers(apiAssembly);
builder.RegisterWebApiFilterProvider(config);
var container = builder.Build();
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
app.UseAutofacMiddleware(container);
app.UseWebApi(config);
I've tried a veriety of options with this in the controller, and in separate classes. The controller is basically:
[RoutePrefix("values")]
public class ValuesController : ApiController
{
//LinkFactory _lf;
//public ValuesController(LinkFactory lf)
//{
// this._lf = lf;
//}
[Route("", Name="valueslist")]
public IEnumerable<string> Get()
{
//UrlHelper h = Request.GetUrlHelper();
//string s2 = h.Link("DefaultApi", new { });
//UrlHelper h = new UrlHelper(Request);
//string s3 = h.Link("DefaultApi", new { });
//Link s4 = _lf.GetUrl("valueslist", new { });
//var helper = ActionContext.Request.GetUrlHelper();
//string s5 = helper.Link("value", new { id = 1});
UrlHelper helper = Request.GetUrlHelper();
string s6 = helper.Link("value", new { id = 1 });
return new string[] { "value1", "value2" };
}
[Route("{id}", Name="value")]
public string Get(int id)
{
return "value";
}
An exception of type 'System.NotImplementedException' occurred in System.Web.dll but was not handled in user code
Additional information: The method or operation is not implemented.
If I take out autofac, it starts working fine. Thanks.
A