How to Use ValueInjecter with Asp.net MVC ViewModel ?

Dec 18, 2012 at 9:19 AM

I have written a Blog post about how to Use ValueInjecter with Asp.net MVC ViewModel.

http://sampathloku.blogspot.com/2012/11/how-to-use-valueinjecter-with-aspnet.html

Your Comments and feedback greatly appreciated. 

Coordinator
Dec 18, 2012 at 9:59 AM

cool, will add it to the frontpage

Coordinator
Dec 18, 2012 at 10:07 AM
Edited Dec 18, 2012 at 10:11 AM

note, another way of doing the FilterId injection would be like this:

 

 

    public class FilterId : ConventionInjection
    {
        protected override bool Match(ConventionInfo c)
        {
            return c.SourceProp.Name != "Id" &&
                   c.SourceProp.Name == c.TargetProp.Name
                   && c.SourceProp.Type == c.TargetProp.Type;
        }
    }
  

or like this:

 

    public class IngnoreProps : ConventionInjection
    {
        private readonly string[] _ignores;

        public IngnoreProps()
        {
        }

        public IngnoreProps(params string[] ignores)
        {
            _ignores = ignores;
        }

        protected override bool Match(ConventionInfo c)
        {
            return (_ignores == null || !_ignores.Contains(c.SourceProp.Name)) &&
                   c.SourceProp.Name == c.TargetProp.Name
                   && c.SourceProp.Type == c.TargetProp.Type;
        }
    }

 

and use it like this:

 

target.InjectFrom(new IgnoreProps("Id"), source);
Dec 18, 2012 at 10:20 AM

Hi Coordinator,

Thanks for Your feedback.

You can have a freedom to use any where.

Dec 18, 2012 at 10:21 AM
o wrote:

cool, will add it to the frontpage

 

Hi Coordinator,

Thanks for Your feedback.

You can have a freedom to use any where.

Dec 18, 2012 at 10:28 AM
o wrote:

note, another way of doing the FilterId injection would be like this:

 

 

    public class FilterId : ConventionInjection
    {
        protected override bool Match(ConventionInfo c)
        {
            return c.SourceProp.Name != "Id" &&
                   c.SourceProp.Name == c.TargetProp.Name
                   && c.SourceProp.Type == c.TargetProp.Type;
        }
    }
  

or like this:

 

    public class IngnoreProps : ConventionInjection
    {
        private readonly string[] _ignores;

        public IngnoreProps()
        {
        }

        public IngnoreProps(params string[] ignores)
        {
            _ignores = ignores;
        }

        protected override bool Match(ConventionInfo c)
        {
            return (_ignores == null || !_ignores.Contains(c.SourceProp.Name)) &&
                   c.SourceProp.Name == c.TargetProp.Name
                   && c.SourceProp.Type == c.TargetProp.Type;
        }
    }

 

and use it like this:

 

target.InjectFrom(new IgnoreProps("Id"), source);

Hi Coordinator,

Thanks for additional Information.

I would like 2nd one.It's a very generic one.So I will definitely update this thing also in my blog post.

Grate work.