title: Localizer dependency Injection without constructor
body: <p>I'm creating custom Authorization in .net core. Everything is working completely fine but I want to add localizer in attribute response. </p>
  
  <p>Below is my code</p>
  
  <pre class="lang-cs prettyprint-override"><code>[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
      public class CustomAuthorizeFilters : AuthorizeAttribute, IAuthorizationFilter
      {
          public CustomAuthorizeFilters()
          { }
  
          public void OnAuthorization(AuthorizationFilterContext context)
          {
              var User = context.HttpContext.User;
  
              if (!User.Identity.IsAuthenticated)
                  return;
  
              using (var account_help = new AccountHelpers(Startup.ConnectionString))
              {
                  var userId = Guid.Parse(new security.AesAlgoridhm().Decrypt(User.Claims.Where(x =&gt; x.Type == JwtRegisteredClaimNames.Sid)?.FirstOrDefault().Value));
                  ProfileResponse user = new ProfileResponse();
  
                  if (user == null)
                      context.Result = new CustomResultFilters("error_access_token_expired", 401);
  
                  if (!user.EmailConfirmed)
                      context.Result = new CustomResultFilters("bad_response_account_not_confirmed", 400);
  
                  if (!user.Active)
                      context.Result = new CustomResultFilters("bad_response_account_inactive", 400);
              }
          }
      }
  </code></pre>
  
  <p>I've tried passing localizer in the constructor like this but when I'm passing an argument from the controller it is giving me error as</p>
  
  <blockquote>
    <p>attribute constructor parameter has type which is not a valid attribute parameter type</p>
  </blockquote>
  
  <pre class="lang-cs prettyprint-override"><code>  IStringLocalizer&lt;dynamic&gt; localize { get; set; }
    public CustomAuthorizeFilters(IStringLocalizer&lt;dynamic&gt; localizer = null)
    {
              localize = localizer;
    }
  </code></pre>
  
  <p>I know attribute only supports primitive datatypes that's why I've also tried injecting direct dependency as </p>
  
  <pre><code>context.HttpContext.RequestServices.GetService(typeof(IStringLocalizer&lt;dynamic&gt;));
  </code></pre>
  
  <p>but that is giving error as:</p>
  
  <blockquote>
    <p>cannot convert from object to localizer.</p>
  </blockquote>