views:

113

answers:

1

Guys, is it possible to get physical path to asp.net mvc 2 application inside Global.asax methods?

UPD: sorry, i forget to say, that I need to get that path in Ninject IoC container configuration.
This is a sketch of what i'm having now:

public class MvcApplication : System.Web.HttpApplication 
{
    ...
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterRoutes(RouteTable.Routes);

        ControllerBuilder.Current.SetControllerFactory(typeof(IOCControllerFactory));
    }
}

public class IOCControllerFactory : DefaultControllerFactory
{
    private readonly IKernel kernel;

    public IOCControllerFactory()
    {
        kernel = new StandardKernel(new NanocrmContainer());
    }

    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        var controller = kernel.TryGet(controllerType) as IController;

        if (controller == null)
            return base.GetControllerInstance(requestContext, controllerType);

        var standartController = controller as Controller;

        return standartController;
    }

    class NanocrmContainer : Ninject.Modules.NinjectModule
    {
        public override void Load()
        {
            Bind<IFileService>().To<BusinessLogic.Services.FileService>().InRequestScope().WithConstructorArgument("temp", "Temp").WithConstructorArgument("docs", "Documents"); // Temp and Documents should be replaced with corresponding paths
        }
    }
}
+1  A: 

You're looking for the HttpRuntime.AppDomainAppPath property.

SLaks
Sorry I wasn't clear enough in the question...
zerkms
You're still looking for the [`HttpRuntime.AppDomainAppPath` property](http://msdn.microsoft.com/en-us/library/system.web.httpruntime.appdomainapppath.aspx), and perhaps `Path.Combine`.
SLaks
`using System.Web;`
SLaks
SLaks: that was my mistake - it was there, and i need glasses :-) thanks
zerkms