Friday, March 11, 2011

Technologies as Girls

ASP.NET


She is quite easy to please. At her age it's no wonder. If you aren’t looking for anything special – she’s totally yours. A bit of dressing-up and tuning and voilà, you have a girlfriend! But if you're not the kind of guy who loves endless repetitive conversations, you ran into trouble… You’ve got to be a real genius to tell her what you really want to do or to understand what she is saying or can do every now and then. She won’t dance to your tune and she most often likes the things that her parents taught her – there are no ifs ands or buts about it, she affords something new with deep breath. And if, on top of that, you happen to be a man of fashion, then dressing her up will be a great strain on your nerves. So you’d better think before you mess up with her.

ASP.NET MVC

She is young and beautiful. Her mind is not burdened with conventionalities and complex rules, and she doesn’t expect her boyfriend to know all the social graces. She is willing to make all sorts of connections and she can maintain them so that her reputation is impeccable. She changes her opinion and behaviour to be a match for capable partners that stick around. Oh, and by the way, you can keep total control over her wardrobe :-)

WinForms


Sometimes you can look at her and take her for some other girl. They all look the same as if they were from incubator. And they bring an air of old times, of something long forgotten. People hardly ever call them beautiful. All right! She might become beautiful… but then she needs a celebrity make-up artist. But such high-flying professionals would rather court the next girl…

WPF


Wow! She would stop a running horse, and rush in a burning house. She can do nearly anything. More than that: she looks stunning… and wait till you see the way she moves… Yes, she may be weird or naughty at times, but if you manage and tame her, the effect will be astonishing. And the only thing you will have to fight with is the temptation to show your friends all you can do with her.

Silverlight


Rejoice, ye nymphet lovers! WPF's little sister has grown up and even come of age in some way, but she has retained her freshness and tiny frame together with the beauty and smoothness of her movements. Yet unlike WPF, she is far less fussy about rendezvous points, less demanding about your financial well-being and sometimes even willing to change her name. So if you have to leave her for ASP.NET (uh-oh! :-( ), you will keep thinking of that air of freedom you relished in communication with her every time you were unbuttoning her blouse and pondering over what you want her to be like this time.


P.S. Couldn't find photo copyrights. Tried to pick out the copiable ones. Offers welcome!
P.P.S. Huge thanks to Kate Melnikova who did a major work of the translation of this text from Russian.

Thursday, February 17, 2011

Forums are evil?

Don't understand me wrong - I'm not against forums, blogs and other community related activities. I just want to consider one usual situation.
Junior developer faced with a problem. And of course as usual this problem has appeared out of the blue where none could expect and caused by not knowing basics of used technology. What does junior do? Start learning the elements - no! Start trying to dig the technology - no! Today everyone knows the magic word "google", "bing" (etc - insert your favourite search engine). Junior quickly hammer the question into the search box and voilà  - they could get answer on some forums!

And now let's look at forums' contingent and even assume that there are some expers in necessary sophere.

An expert open forum, sees junior's question and moaning "ohh, lamers have completely cowed me" and skips it.
Another junior opens forum, sees the complex (from their point of view) querstion and starts reasoning.

Results usually are regrettable. Answer could be obtained, but there is no guarantee that it would be right. And I repeat - it's not always! And yes, sometimes you can get an answer from the man who thinks in right direction. And sometimes questions are not lame. But all my many years experience of juniors upbringing cries: "Learn the basics!!!"

P.S. There are some communities like experts-exchange, in which it's much easier to find right answers and where much more experts. I was registered there and obtained the status of expert, but it's a pity, to support this status you need time but not all seniors have it :(

So, forums are not evil if you are ready and if it's a right forum :)

RUS: http://asliborsky-ru.blogspot.com/2011/02/blog-post.html

Thursday, December 17, 2009

All Validation Techniques in ASP.NET MVC

Authors and editors: Sergey Khalipsky, Aleksandr Sliborsky
In the first article (Validation Techniques Comparison) we just considered the most useful and the best techniques that could be used for validation implementation in ASP.NET MVC.
We don’t want to deprive you of a pleasure of doing all this by yourself, so we will just give you a direction and some samples of implementation and let you dig deeper .
So, today’s agenda is:
  1. Manual validation in Model Binder and Controllers (client validation type 1 and server validation type 1)
  2. DataAnnotations (client validation type 2, server validation type 2);
  3. Custom Validation engine implementation (client validation type 1, server validation type 2);
  4. Spring Validation Framework usage on a server, manual validation on a client (client validation type 1, server validation type 3)
  5. Spring Validation Framework usage on a server, DataAnnotations + manual validation on a client (it’s a mix from several points from previous review);
  6. xVal Validation Framework
Let’s start fingerscrossed

Tuesday, December 15, 2009

Advanced validation techniques in ASP.NET MVC


Authors and editors: Khalipsky Sergey, Sliborsky Aleksandr

Introduction

When you start development using new technology or framework several questions are arisen: how does it support work with RDBS, how to implement UI better etc.
And, of course, – Validation.
There are several solutions on how to implement validation in the projects based on ASP.NET MVC. When our company first time faced with the ability to implement a solution based on this technology we made an analysis of all viable possibilities. This article and some upcoming articles are the results of those investigations. In this, first article we will consider more theoretical questions and just consider why we have chosen this or that approach in validation. In the next article we will consider implementation of different approaches.

Monday, December 14, 2009

SharePoint Security. Part 1. Introduction


When our company involved into SharePoint development as Security consultants or when we asked to improve legacy system we very often shocked by the level of security of that systems and by the implementation efforts applied to it. Sometimes it seems that all we are working in trust environment where everyone is a saint and there is no thefts, corruptions and other sins.
We prepared the series of articles which should help in security implementation and design in SharePoint portals. This is only the first one from this series.

Monday, December 7, 2009

ASP.NET MVC WebForms vs Spark View Engines. Part 2. Markup

In my previous article (ASP.NET MVC WebForms vs Spark View Engine. Part 1) I had started to describe the differences between standard ASP.NET MVC View Engine and spark. In this short article I will just show the differences between implementation of 3 equal pages.
So, less words, more code…

Friday, December 4, 2009

ASP.NET WebForms vs Spark View Engine. Part 1


Preamble

There is no "the best", "one fits all" engine, framework or something else. I didn't try to choose the best, I just tried to investigate the possibilities to have them in mind for line of the upcoming projects and to have a possibility to choose between them depending on the requirements.
Also, I’m not a guru in both engines, I had just made a surface comparison and appreciate any comments, fixes and additions!

Monday, September 22, 2008

What's wrong with Spring.Net Interceptors?

When I began using of Spring.Net interceptors part of my code stopped working! For example such code:


public class POBlo
{
    private IDataProvider _dataProvider = null;
    // Yes, I know about auto property :)
    protected virtual IDataProvider DataProvider
    {
        get { return _dataProvider; }
        set { _dataProvider = value; }
    }
 
    public virtual void Save (Entity entity)
    {
        // Here we have NullReferenceException :(
        DataProvider.Save (entity);
    }
}

Before I added interceptor all were OK. I could save entity and no exception was occurred.

After some investigation I've found the problem: intercepted target object has right value of this property but proxy object does not expose it!
Finally I opened Spring.Net sources and found the Spring.Proxy.AbstractProxyTypeBuilder's InheritType method the proxies my class:



protected virtual void InheritType(TypeBuilder typeBuilder,
            IProxyMethodBuilder proxyMethodBuilder, Type type, bool declaredMembersOnly)
{
    IDictionary methodMap = new Hashtable();
    IList finalMethods = new ArrayList();
 
    BindingFlags bindingFlags = BindingFlags.Public  BindingFlags.Instance;
    if (declaredMembersOnly)
    {
        bindingFlags = BindingFlags.DeclaredOnly;
    }
 
    // override virtual methods
    MethodInfo[] methods = type.GetMethods(bindingFlags);
    foreach (MethodInfo method in methods)
    {
        if (method.IsVirtual && !method.IsFinal)
        {
            MethodBuilder methodBuilder = proxyMethodBuilder.BuildProxyMethod(method, null);
            ApplyMethodAttributes(methodBuilder, method);
            methodMap[method.Name] = methodBuilder;
        }
    }
    // override virtual properties
    foreach (PropertyInfo property in type.GetProperties(bindingFlags))
    {
        ImplementProperty(typeBuilder, type, property, methodMap);
    }
    // override virtual events
    foreach (EventInfo evt in type.GetEvents(bindingFlags))
    {
        ImplementEvent(typeBuilder, type, evt, methodMap);
    }
}

As you can see, Spring's default implementation creates proxy just for publicly published interfaces of the class. So first obvious solution is to mark all properties "public" instead of "protected". But this is unacceptable because of different reasons: huge reworking and (what is more important) encapsulation violation.

So I've decided to just reimplement this solution. This is quite easy with DI and Spring.Net. Simply follow the steps:
1. Create custom ProxyTypeBuilder.
2. Create custom ProxyFactory
3. Register ProxyFactory in configs.




Create custom ProxyTypeBuilder

Create custom proxy type builder where we define necessary binding flags.



 
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Aop;
using Spring.Aop.Framework;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Proxy;

namespace Qulix.Spring.Aop
{
    /// 
    /// Implements proxy type builder that uses inheritance and exposes not only public methods
    /// 
    [CLSCompliant(false)]
    public class CustomInheritanceProxyTypeBuilder : DecoratorAopProxyTypeBuilder
    {
        #region IProxyTypeBuilder Members
        [CLSCompliant(false)]
        protected override void InheritType(TypeBuilder typeBuilder,
                                            IProxyMethodBuilder proxyMethodBuilder, Type type, bool declaredMembersOnly)
        {
            IDictionary methodMap = new Hashtable();
            BindingFlags bindingFlags = BindingFlags.NonPublic  BindingFlags.Public  BindingFlags.Instance;
            if (declaredMembersOnly)
            {
                bindingFlags = BindingFlags.DeclaredOnly;
            }
            // override virtual methods
            MethodInfo[] methods = type.GetMethods(bindingFlags);
            foreach (MethodInfo method in methods)
            {
                if (method.IsVirtual && !method.IsFinal)
                {
                    MethodBuilder methodBuilder = proxyMethodBuilder.BuildProxyMethod(method, null);
                    ApplyMethodAttributes(methodBuilder, method);
                    methodMap[method.Name] = methodBuilder;
                }
            }
            // override virtual properties
            foreach (PropertyInfo property in type.GetProperties(bindingFlags))
            {
                ImplementProperty(typeBuilder, type, property, methodMap);
            }
            // override virtual events
            foreach (EventInfo evt in type.GetEvents(bindingFlags))
            {
                ImplementEvent(typeBuilder, type, evt, methodMap);
            }
        }
        #endregion
    }
}


As you can see I've added extra BindingFlags. This will allow to find and proxy not only public properties and methods.


Create custom proxy factory


Just inherit from one of the implemented Proxy factories and reimplement CreateAopProxy method:



[Serializable]
[CLSCompliant(false)]
public class InheritanceAopProxyFactory : DefaultAopProxyFactory
{
    [CLSCompliant(false)]
    public override IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
    {
        if (advisedSupport == null)
        {
            throw new AopConfigException("Cannot create IAopProxy with null ProxyConfig");
        }
        if (advisedSupport.Advisors.Length == 0 && advisedSupport.TargetSource == EmptyTargetSource.Empty)
        {
            throw new AopConfigException("Cannot create IAopProxy with no advisors and no target source");
        }
 
        IProxyTypeBuilder typeBuilder = new CustomInheritanceProxyTypeBuilder(advisedSupport);
        Type aopProxy = BuildProxyType(typeBuilder);
        ConstructorInfo constructor = aopProxy.GetConstructor(new Type[] { typeof(IAdvised) });
        return (IAopProxy)constructor.Invoke(new object[] { advisedSupport });
    }
}

Here we just replace creation of ProxyTypeBuilder with our own CustomInheritanceProxyTypeBuilder. Of course, you can parametrize you ProxyFaxtory to accept type of the ProxyTypeBuilder. I do not implement this functionality for simplicity.


Register ProxyFactory in cofig


As last step we need to define what IAopProxyFactory implementation will be used. For this purpose write in the configuration file the following:


 
<object id="IAopProxyFactory" type="Qulix.Spring.Aop.InheritanceAopProxyFactory, Qulix.Spring" />
 

That's it. Now we just need to define the reference to our ProxyFactory implementation. For example:



<object id="POBloProxier" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
    <property name="AopProxyFactory" ref="IAopProxyFactory" />
...

I hope this will help you. And you will help me to find easier and more clearer solution.

kick it on DotNetKicks.com
Share this Post:

Facebook
Digg DelIcioUs