<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 5, 2015 at 5:07 PM, luiz americo pereira camara <span dir="ltr"><<a href="mailto:luizmed@oi.com.br" target="_blank">luizmed@oi.com.br</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>Starting a new thread.<br><br>2015-01-05 15:16 GMT-03:00 silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span><div class="gmail_quote">On Mon, Jan 5, 2015 at 12:54 PM, Marco van de Voort <span dir="ltr"><<a href="mailto:marcov@stack.nl" target="_blank">marcov@stack.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
As a first step in the 3.0.0 release process the stable branch was branched<br>
off to branches/fixes_3_0 and the version number was updated to 3.0.1<br>
<br>
The version in trunk was raised to 3.1.1<br>
<br>
Scripts might need modification accordingly.</blockquote></div><div><br></div></span><div>Good news!</div><div><br></div><div>Chances of custom attributes[1] (or something like this) in release 3.0? I have plans to use IoC[2] and DI using this feature.</div><div><br></div></div></div></blockquote><div> </div>I created a IoC Container that can be found at <a href="https://code.google.com/p/luipack/source/browse/trunk/luicomponents/luiioccontainer.pas" target="_blank">https://code.google.com/p/luipack/source/browse/trunk/luicomponents/luiioccontainer.pas</a> . It has no dependencies.<br></div></div></div></blockquote><div><br></div><div>Awesome!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div></div>With it is possible to implement Service Locator and Property Injection patterns. Constructor Injection is not possible due to lacking of Extended RTTI support in fpc.<br></div></div></blockquote><div><br></div><div>Can you send a small (and isolated) sample showing how to use it?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div></div><div>While the C# crowd  praises the Constructor Injection pattern ( <a href="http://www.devtrends.co.uk/blog/how-not-to-do-dependency-injection-the-static-or-singleton-container" target="_blank">http://www.devtrends.co.uk/blog/how-not-to-do-dependency-injection-the-static-or-singleton-container</a> ), i had hard times figuring how it would work in real world / Lazarus projects. Also, polluting the constructor  signature is not something that i like. And finally with Constructor Injection is not possible to use with TComponent / TForm<br><br>So in the end, i use the service locator and have plans to use Property Injection pattern<br><br></div><div>BTW: Custom Attributes support would help to have a nicer Property Injection implementation</div></div></blockquote><div><br></div><div>I've plan to use something like this (CDI inspirations: <a href="http://cdi-spec.org">http://cdi-spec.org</a>):</div><div><br></div><div>The model:</div><div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><span style="color:rgb(167,29,93)">uses</span>
  My.Company.MySDK.EntityAttributes, My.Company.MySDK.TableAttributes ...;

<span style="color:rgb(167,29,93)">type</span>
  [Entity]
  [Table(<span style="color:rgb(223,80,0)"><span>'</span>products<span>'</span></span>)]
  TProduct = <span style="color:rgb(167,29,93)">class</span>(TObject)
  <span style="color:rgb(167,29,93)">public</span>
    [Id][GeneratedValue]
    <span style="color:rgb(167,29,93)">property</span> Id: LongInt ...;
    [ManyToOne][JoinColumn(<span style="color:rgb(223,80,0)"><span>'</span>OrderId<span>'</span></span>)]
    <span style="color:rgb(167,29,93)">property</span> OrderId: LontInt ...;
    [NotNull][NotEmpty][Size(<span style="color:rgb(0,134,179)">1</span>, <span style="color:rgb(0,134,179)">10</span>)][Unique]
    <span style="color:rgb(167,29,93)">property</span> <span style="color:rgb(167,29,93)">Name</span>: String ...;    
    [Nulls][Lenght(<span style="color:rgb(0,134,179)">100</span>)][Unique]
    <span style="color:rgb(167,29,93)">property</span> Description: String ...;
    [MyCustomCurrConversion(TypeInfo(Currency), TypeInfo(String), <span style="color:rgb(223,80,0)"><span>'</span>,0.00<span>'</span></span>)]
    [MyCustomMinMax(<span style="color:rgb(223,80,0)"><span>'</span>Price must be >= %d and <= %d.<span>'</span></span>, [<span style="color:rgb(0,134,179)">1</span>, <span style="color:rgb(0,134,179)">1000</span>])]
    <span style="color:rgb(167,29,93)">property</span> Price: Currency ...;
  <span style="color:rgb(167,29,93)">end</span>;</pre></div><div><br>The DAO:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><span style="color:rgb(167,29,93)">type</span>
  [RequestScoped]
  TProductDao = <span style="color:rgb(167,29,93)">class</span>(TObject)
  <span style="color:rgb(167,29,93)">private</span>
    [Inject] <span style="color:rgb(167,29,93)">property</span> Session: TSession ... ;
    [Transational] <span style="color:rgb(167,29,93)">procedure</span> <span style="color:rgb(121,93,163)">Add</span>(AProduct: TProduct);
    ...
  <span style="color:rgb(167,29,93)">end</span>;
...
<span style="color:rgb(167,29,93)">procedure</span> <span style="color:rgb(121,93,163)">TProductDao.Add</span>(AProduct: TProduct);
<span style="color:rgb(167,29,93)">begin</span>
  Session.Save(AProduct);
<span style="color:rgb(167,29,93)">end</span>;</pre></div><div><br></div><div>The <i>produces</i> (to use external libs like <b>JCore</b>):</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><span style="color:rgb(167,29,93)">type</span>
  [ApplicationScoped]
  TSessionCreator = <span style="color:rgb(167,29,93)">class</span>(TObject)
  <span style="color:rgb(167,29,93)">private</span>
    [Inject] <span style="color:rgb(167,29,93)">property</span> SessionFactory: TJCoreSession ... ;
    [Produces] <span style="color:rgb(167,29,93)">function</span> <span style="color:rgb(121,93,163)">GetSession</span>: TSession;
...
  <span style="color:rgb(167,29,93)">end</span>;
...
TSessionCreator.GetSession: TSession;
<span style="color:rgb(167,29,93)">begin</span>
  Result := ASessionFactory.OpenSession;
<span style="color:rgb(167,29,93)">end</span>;

TSessionCreator.Close([Disposes]ASession: TSession) <span style="color:rgb(150,152,150)">{</span>
<span style="color:rgb(150,152,150)">begin</span>
<span style="color:rgb(150,152,150)">  if ASession.IsOpen</span>
<span style="color:rgb(150,152,150)">    ASession.Close;</span>
<span style="color:rgb(150,152,150)">end;</span></pre></div><div><br></div><div>The controller:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><span style="color:rgb(167,29,93)">uses</span>
  My.Company.ControllerAttributes ... ;

<span style="color:rgb(167,29,93)">type</span>
  [Controller]
  TProcuctController = <span style="color:rgb(167,29,93)">class</span>(TObject)
  <span style="color:rgb(167,29,93)">public</span>
    [Post][Transational] <span style="color:rgb(167,29,93)">procedure</span> <span style="color:rgb(121,93,163)">Add</span>([Valid] AProduct: TProduct); <span style="color:rgb(150,152,150)">// [Valid]: to validade properties</span>
    [Get][Path(<span style="color:rgb(223,80,0)"><span>'</span>./product<span>'</span></span>)][Transational] <span style="color:rgb(167,29,93)">procedure</span> <span style="color:rgb(121,93,163)">List</span>([Pagination(<span style="color:rgb(223,80,0)"><span>'</span>page={[0-9]}&rows={[0-9]}<span>'</span></span>)] AProducts: TArrayList<TProduct>); <span style="color:rgb(150,152,150)">// to paginate products</span>
    [Inject] <span style="color:rgb(167,29,93)">property</span> ProductDao: TProductDao ...; <span style="color:rgb(150,152,150)">// inject DAO</span>
    [Inject] <span style="color:rgb(167,29,93)">property</span> Result: TResponse ...; <span style="color:rgb(150,152,150)">// inject Response</span>
  <span style="color:rgb(167,29,93)">end</span>;
...

<span style="color:rgb(167,29,93)">procedure</span> <span style="color:rgb(121,93,163)">TProcuctController.Add</span>(AProduct: TProduct);
<span style="color:rgb(167,29,93)">begin</span>
  ProductDao.Add(AProduct);
  Result.SetAttribute(AProduct, <span style="color:rgb(223,80,0)"><span>'</span>product<span>'</span></span>).RedirectTo(TProductController).List;
<span style="color:rgb(167,29,93)">end</span>;

<span style="color:rgb(167,29,93)">procedure</span> <span style="color:rgb(121,93,163)">TProcuctController.List</span>(AProducts: TArrayList<TProduct>);
<span style="color:rgb(167,29,93)">begin</span>
  Result.SetAttribute(AProducts, <span style="color:rgb(223,80,0)"><span>'</span>products<span>'</span></span>); <span style="color:rgb(150,152,150)">// to create a variable "products" in my BSP view</span>
<span style="color:rgb(167,29,93)">end</span>;</pre></div><div><br></div><div>The view:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><<span style="color:rgb(99,163,92)">html</span>>
<<span style="color:rgb(99,163,92)">ul</span>>
<<span style="color:rgb(99,163,92)">c:forEach</span> <span style="color:rgb(121,93,163)">items</span>=<span style="color:rgb(223,80,0)"><span>"</span>${products}<span>"</span></span> <span style="color:rgb(121,93,163)">var</span>=<span style="color:rgb(223,80,0)"><span>"</span>product<span>"</span></span>>
    <<span style="color:rgb(99,163,92)">li</span>> ${<a href="http://product.name" target="_blank">product.name</a>} - <<span style="color:rgb(99,163,92)">fmt:currency</span> <span style="color:rgb(121,93,163)">value</span>=<span style="color:rgb(223,80,0)"><span>"</span>${product.price}<span>"</span></span> <span style="color:rgb(121,93,163)">mask</span>=<span style="color:rgb(223,80,0)"><span>"</span>R$ ,0.00<span>"</span></span>/></<span style="color:rgb(99,163,92)">li</span>>
</<span style="color:rgb(99,163,92)">c:forEach</span>>
</<span style="color:rgb(99,163,92)">ul</span>>
</<span style="color:rgb(99,163,92)">html</span>></pre></div><div><br></div><div>But I think that I'll still wait some years to make it possible in Free Pascal hehe ...<br></div><div><br></div></div>-- <br><div>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>