Hi mahesh213,
In MyAuthenticationFilter set class instance to public.
Refer below example.
MyAuthenticationFilter
public class MyAuthenticationFilter : ActionFilterAttribute, IAuthenticationFilter
{
public CustomerRepository _customerRepository = new CustomerRepository();
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
}
public void OnAuthentication(AuthenticationContext filterContext)
{
}
}
public class CustomerRepository
{
public int Id { get; set; }
}
Class
public class Customer
{
MyAuthenticationFilter myAuthenticationFilter = new MyAuthenticationFilter();
public CustomerRepository GetObjectValues()
{
CustomerRepository repos = myAuthenticationFilter._customerRepository;
repos.Id = 1;
return repos;
}
}
Controller
public class HomeController : Controller
{
public ActionResult Index()
{
Customer customer = new Customer();
ViewBag.Message = customer.GetObjectValues().Id;
return View();
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@if (ViewBag.Message!=null)
{
@ViewBag.Message
}
</body>
</html>