Reputation: 45911
I'm developing an ASP.NET MVC 4 Web Api application with C# and .NET Framework.
My question is very easy. This is my Global.asax
class.
Global.asax:
public class WebApiApplication : System.Web.HttpApplication
{
public MyClass MyClassVM
{
get { return Singleton.MyClassVM; }
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
And I want to get access to MyClassVM
on my ApiController
. How can I do that?
Upvotes: 0
Views: 1126
Reputation: 7804
Is there any particular reason that you are introducing an indirection here? If not, I do not see why you cannot use the singleton directly from your controller like so:
public IHttpActionResult Get()
{
Singleton.MyClassVM...
}
Otherwise could you not make the MyClassVM
property static
and then access it via the type from the controller?
Upvotes: 1