Вопрос по .net, ninject, dependency-injection, c#, asp.net-mvc – Использование внедрения зависимостей в ASP.NET MVC3 Model Binder

8

Error: User Rate Limit Exceeded

public class UserModelBinder : IModelBinder
{
    //[Inject]
    public UserDataService userData { get; set; }

    public object BindModel(
        ControllerContext controllerContext,
        ModelBindingContext bindingContext)
    {
        Guid UserID =
            (Guid)Membership.GetUser().ProviderUserKey;

        //userDataService = DependencyResolver.Current
        //    .GetService<UserDataService>();

        User user = userDataService.GetUser(UserID);

        return user;
    }
}

noticed the commented lines of code?

Error: User Rate Limit ExceededGlobal.asaxError: User Rate Limit Exceeded

ModelBinders.Binders[typeof(User)] = new UserModelBinder();

Error: User Rate Limit Exceeded

UserDataServiceError: User Rate Limit ExceededUserDataService -> UserRepository -> ContextError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded[Inject]Error: User Rate Limit ExceededuserDataError: User Rate Limit Exceeded

(could it be that UserDataService does not have an interface and I'm binding the object to itself: kernel.Bind<UserDataService>().ToSelf(); ??)

Error: User Rate Limit Exceeded

userDataService = DependencyResolver.Current
    .GetService<UserDataService>();

Error: User Rate Limit ExceededuserDataService = new UserDataService()

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded marc_s
Error: User Rate Limit Exceeded JConstantine
Error: User Rate Limit Exceeded marc_s
Error: User Rate Limit Exceeded Steven
Error: User Rate Limit Exceededbeefycode.com/post/Dependency-Infection.aspx trailmax

Ваш Ответ

3   ответа
6

Guid userIduserDataService.GetUser(UserID);

Error: User Rate Limit Exceeded trailmax
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded trailmax
Error: User Rate Limit Exceeded
4

public class UserModelBinder : IModelBinder
{
    public Func<UserDataService> UserData { get; set; }

    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        Guid UserID = (Guid)Membership.GetUser().ProviderUserKey;

        User u = UserData().GetUser(UserID);

        return u;
    }
}

ModelBinders.Binders[typeof(User)] = new UserModelBinder() 
{  
    userData = () => DependencyResolver.Current.GetService<UserDataService>();
}

UserModelBinder

ICurrentUserContext

1

DependencyResolver.CurrentmuchnewUserDataService

DependencyResolver.CurrentIDependencyResolver

IControllerActivator

Error: User Rate Limit Exceeded trailmax
Error: User Rate Limit Exceededblog.objectmentor.com/articles/2010/01/17/…

Похожие вопросы