Web Api 2 Autofac AuthorizeAttribute Property Injection Doesnt Work

402 views
Skip to first unread message

temre...@gmail.com

unread,
Jan 25, 2017, 11:19:12 AM1/25/17
to Autofac
Trying to inject property to my custom AuthorizeAttribute but this attribute always comes null. Is this registration wrong?

public class AuthenticateAttribute : AuthorizeAttribute
{
public IAuthenticationService authenticationService { get; set; }
public UserTypes UserType;
public AuthenticateAttribute()
{

}
}

**Calling From Global Asax**

public static void InitializeDependencies()
{
var builder = new ContainerBuilder();
var config = GlobalConfiguration.Configuration;
builder.RegisterAssemblyTypes(Assembly.Load("BusinessServices"))
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(Assembly.Load("BusinessEntities"))
.Where(t => t.Name.EndsWith("Helper"))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config);
builder.Register(x => new ApiExceptionHandler(x.Resolve<ILogService>())).AsWebApiExceptionFilterFor<ApiController>().InstancePerLifetimeScope();
builder.RegisterType<AuthenticateAttribute>().PropertiesAutowired().InstancePerLifetimeScope();
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}

http://stackoverflow.com/questions/41842119/web-api-2-autofac-authorizeattribute-property-injection-doesnt-work

Travis Illig

unread,
Jan 25, 2017, 11:22:38 AM1/25/17
to Autofac, temre...@gmail.com
Please don't cross-post questions to the newsgroup. Folks who answer questions for Autofac monitor StackOverflow and that's the best way to go to avoid multiple people working on the same thing in different places. If someone has an answer, we can follow up there.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages