[picocontainer-dev] RE: Desired behavior for Picocontainer and Static injection
"Michael Rimov" <[email protected]> Mon, 10 Jun 2013 12:53:44 -0700
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Organization | Centerline Computers, Inc. |
| Message-ID | <[email protected]> |
------=_NextPart_000_024D_01CE65D9.8B5ED680
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
>1) Could the root-most container permanently turn off static injection for
subsequent child containers ?
If you want to completely enforce no static injection:
new JSRPicoContainer(new AdaptingInjection() {
protected boolean allowStaticInjection() {
return false;
}
});
OR because the state variable that will keep track of what classes have been
statically initialized is only going to set in JSRPicoContainer
new DefaultPicoContainer(new AdaptingInjection());
will work as well, but you lose automatic key generation and automatic
caching management based on the annotations this way.
2) Like #1, but for any subsequent container whether child or not.
pico.makeChildContainers()
will propagate ComponentAdapterFactories like normal, so whatever behavior
you have will propagate.
Otherwise, if you manually construct your own container:
new DefaultPicoContainer(new AdaptingInjection() { ... }, parentContainer)
to force no static injection.
3) What about serialization de-serialization for containers that do or don't
have static injection turned on, and if that could override previous
all-container settings?
Don't know what the current rules for ComponentAdapterFactories are. It
would follow whatever we have already in place since it's just another
ComponentAdapterFactory + InjectionAdapter and explicitly turned on by a
property.
4) Does STATIC_INJECTION as you're designing it, transcend scopes of
containers somewhat ? Or is it a scope in itself that's parent of
"Application scope" (called singleton scope in other containers)?
Well the state mechanism I'm going to use will sit as an instance variable
in a JSRPicoContainer. So if you have:
appScopeContainer.as(Characteristics.STATIC_INJECTION).addComponent(A.class)
;
and
requestScopeContainer.as(Characteristics.STATIC_INJECTION).addComponent(A.cl
ass);
Then the static methods are going to initialize twice.
I have no interest in sharing state between Picocontainers in such a way so
that statics (clearly an edge case and a mediocre one at that) are
guaranteed to initialize only once across multiple containers.
The way I'm designing it will pass the TCK (since it only uses one
container), and I think that's good enough. To completely guarantee
only-once initialization across multiple containers, I think I'd need to
either resort to static state variables in containers. (ICK!), or bytecode
modification to pass the state off to the actually class. I personally
don't think adding a bytecode modification library for an edge case is a
good reason to further bloat Pico.
Additionally, since static initialization is an OPTIONAL feature of the JSR,
I think it's worth it to say we support static initialization with a few
caveats and if the joker that LOVES static initialization gets ticked off @
Picocontainer , so be it. But if some poor sot is stuck with static
initialization because of the code he inherited, I'd say let's be merciful
to him and give him a way to get it done.
-Mike
------=_NextPart_000_024D_01CE65D9.8B5ED680
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 14 =
(filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><div><p class=3DMsoNormal><span =
style=3D'color:#1F497D'>></span>1) Could the root-most container =
<u>permanently</u> turn off static injection for subsequent child =
containers ?<span style=3D'color:#1F497D'><o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><div><div><p class=3DMsoNormal><span =
style=3D'color:#1F497D'>If you want to completely enforce no static =
injection:<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'color:#1F497D'><o:p> </o:p></span></p><p =
class=3DMsoNormal><span style=3D'color:#1F497D'>new JSRPicoContainer(new =
AdaptingInjection() {<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'color:#1F497D'> &=
nbsp; protected boolean allowStaticInjection() =
{<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'color:#1F497D'> &=
nbsp; &n=
bsp; return false;<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'color:#1F497D'> &=
nbsp; }<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'color:#1F497D'>});<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'color:#1F497D'><o:p> </o:p></span></p><p =
class=3DMsoNormal><span style=3D'color:#1F497D'>OR because the state =
variable that will keep track of what classes have been statically =
initialized is only going to set in =
JSRPicoContainer<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'color:#1F497D'><o:p> </o:p></span></p><p =
class=3DMsoNormal><span style=3D'color:#1F497D'>new =
DefaultPicoContainer(new AdaptingInjection());<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'color:#1F497D'><o:p> </o:p></span></p><p =
class=3DMsoNormal><span style=3D'color:#1F497D'>will work as well, but =
you lose automatic key generation and automatic caching management based =
on the annotations this way.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'color:#1F497D'><o:p> </o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p></div><div><p class=3DMsoNormal>2) Like =
#1, but for any subsequent container whether child or =
not.<o:p></o:p></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>pico.makeChildContainers()<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>will propagate ComponentAdapterFactories like normal, so whatever =
behavior you have will propagate.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'> Otherwise, if you manually construct your own =
container:<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>new DefaultPicoContainer(new AdaptingInjection() { ….. }, =
parentContainer) to force no static =
injection.<o:p></o:p></span></p></div><div><p =
class=3DMsoNormal><o:p> </o:p></p></div><div><p =
class=3DMsoNormal>3) What about serialization de-serialization for =
containers that do or don't have static injection turned on, and if that =
could override previous all-container settings? <o:p></o:p></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Don’t know what the current rules for ComponentAdapterFactories =
are. It would follow whatever we have already in place since =
it’s just another ComponentAdapterFactory + InjectionAdapter and =
explicitly turned on by a =
property.<o:p></o:p></span></p></div></div><div><p =
class=3DMsoNormal><o:p> </o:p></p></div><div><p =
class=3DMsoNormal>4) Does STATIC_INJECTION as you're designing it, =
transcend scopes of containers somewhat ? Or is it a scope in =
itself that's parent of "Application scope" (called singleton =
scope in other containers)?<o:p></o:p></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Well the state mechanism I’m going to use will sit as an =
instance variable in a JSRPicoContainer. So if you =
have:<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>appScopeContainer.as(Characteristics.STATIC_INJECTION).addComponent(A.=
class);<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>and<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>requestScopeContainer.as(Characteristics.STATIC_INJECTION).addComponen=
t(A.class);<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Then the static methods are going to initialize twice. =
<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>I have no interest in sharing state between Picocontainers in such a =
way so that statics (clearly an edge case and a mediocre one at that) =
are guaranteed to initialize only once across multiple =
containers.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>The way I’m designing it will pass the TCK (since it only uses =
one container), and I think that’s good enough. To =
completely guarantee only-once initialization across multiple =
containers, I think I’d need to either resort to static state =
variables in containers. (ICK!), or bytecode modification to pass the =
state off to the actually class. I personally don’t think =
adding a bytecode modification library for an edge case is a good reason =
to further bloat Pico. <o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Additionally, since static initialization is an <i>OPTIONAL</i> =
feature of the JSR, I think it’s worth it to say we support static =
initialization with a few caveats and if the joker that LOVES static =
initialization gets ticked off @ Picocontainer , so be it. =
But if some poor sot is stuck with static initialization =
because of the code he inherited, I’d say let’s be merciful =
to him and give him a way to get it done.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'> &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p;  =
; -Mike<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p> </o:p></span></p></div></div></div></body></html>
------=_NextPart_000_024D_01CE65D9.8B5ED680--