Re: T5.0.6 about Tapestry ioc

2007-11-16 Thread Howard Lewis Ship
It's roughly this:

@Scope("perthread")
public Transport buildHttpTransport(HttpServletRequest request) {
  return new HttpTransport(request.getAddress(), request.getPort(),
request.isSecure());
}


Actually, you can't directly inject HttpServletRequest (you can inject
Tapestry's Request, and its possible to change things so that
HttpServletRequest is injectable; see TapestryModule).

The point is ... a service builder method can perform the necessary
transformations.

And you want this service to be perthread (there's a constant you can
use in lieu of the "pertread" string there).

On Nov 16, 2007 3:01 AM, lyifan <[EMAIL PROTECTED]> wrote:
>
> I want to implement a service:
>
> public interface Transport {
> public void send();
> }
>
> public class HttpTransport implement Transport {
> private String _address;
> private int _port;
> private boolean _ssl;
> public HttpTransport (String address, int port, boolean ssl) {
>  _address = address;
>  _port = port;
>  _ssl = ssl;
> }
>
> public void send) {
> // ..
> }
> }
>
> The parameter of the constructor is from http request. How can I build this
> service? I know I can use setters, but I just wanna know how to build a
> service using constructor.
> --
> View this message in context: 
> http://www.nabble.com/T5.0.6-about-Tapestry-ioc-tf4820490.html#a13791068
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50

Creator Apache Tapestry and Apache HiveMind

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5.0.6 about Tapestry ioc

2007-11-16 Thread Chris Lewis
You can do what you want, and should do whatever seems sensible for your 
needs. What I'm getting at is that T5 IoC can transparently handle 
creating services with constructor arguments, if those arguments are of 
types known to the container. String won't work, and I honestly don't 
know what would happen if you tried to pass one in, but it won't give 
you what you need. I think the container's object resolution relies on 
mapping a type to a single known instance, but I could be way off here.


I think what you need is to build your service in a builder and manually 
pass it arguments. Of course if these object is based on the current 
request, that's a different story. Be sure to read:


http://tapestry.apache.org/tapestry5/tapestry-ioc/module.html

Sincerely,
chris

lyifan wrote:

Hi Chris,

Do you mean that any constructor parameters can be replaced by an object
that provides those parameters?
for an instance, if address, port, ssl are saved in a config file, I have to
pass a ConfigFile object as the parameter of the HttpTransport constructor.
Am I right?

thank you


Chris Lewis-5 wrote:
  
I'm not sure I understand the constructor parameters. Do you mean they 
come from some other object (HttpRequest)? If so, why not just take 
HttpRequest as a constructor argument? If you do that then you can auto 
bind this service and IoC will know how to create it. If you insist on 
the parameters currently listed, then you'll need to have a service 
builder method, and inject HttpRequest as an argument into that method.


lyifan wrote:


I want to implement a service:

public interface Transport {
public void send();
}

public class HttpTransport implement Transport {
private String _address;
private int _port;
private boolean _ssl;
public HttpTransport (String address, int port, boolean ssl) {
 _address = address;
 _port = port;
 _ssl = ssl;
}

public void send) {
// ..
}
}

The parameter of the constructor is from http request. How can I build
this
service? I know I can use setters, but I just wanna know how to build a
service using constructor.
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






  




Re: T5.0.6 about Tapestry ioc

2007-11-16 Thread lasitha
On Nov 16, 2007 6:36 PM, lyifan <[EMAIL PROTECTED]> wrote:
>
> for an instance, if address, port, ssl are saved in a config file, I have to
> pass a ConfigFile object as the parameter of the HttpTransport constructor.
>

Are you just looking for a way to configure an HttpTransport instance
with prescribed values?
If so, ioc Symbols may be what you're looking for:
http://tapestry.apache.org/tapestry5/tapestry-ioc/symbols.html

On the other hand, you mentioned in your OP that these values come
from the HttpRequest, so perhaps you have a different need altogether?

What's the lifespan of an HttpTransport instance?  Where do the
address, port and ssl values come from, and _when_?

As Chris mentioned, the TapestryModule makes a per-thread Request
available to you, so getting the container to build and inject a
per-thread HttpTransport instance would be easy, if thats what you're
looking for: add a builder method to your app module that takes in
Request, mark it as per-thread with @Scope, have it instantiate and
return an HttpTransport instance and have this injected into your
page/component.
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/Request.html

Don't know if any of that helps - we may need a little more context to
understand your question.

Cheers,
lasitha

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5.0.6 about Tapestry ioc

2007-11-16 Thread lyifan

Hi Chris,

Do you mean that any constructor parameters can be replaced by an object
that provides those parameters?
for an instance, if address, port, ssl are saved in a config file, I have to
pass a ConfigFile object as the parameter of the HttpTransport constructor.
Am I right?

thank you


Chris Lewis-5 wrote:
> 
> I'm not sure I understand the constructor parameters. Do you mean they 
> come from some other object (HttpRequest)? If so, why not just take 
> HttpRequest as a constructor argument? If you do that then you can auto 
> bind this service and IoC will know how to create it. If you insist on 
> the parameters currently listed, then you'll need to have a service 
> builder method, and inject HttpRequest as an argument into that method.
> 
> lyifan wrote:
>> I want to implement a service:
>>
>> public interface Transport {
>> public void send();
>> }
>>
>> public class HttpTransport implement Transport {
>> private String _address;
>> private int _port;
>> private boolean _ssl;
>> public HttpTransport (String address, int port, boolean ssl) {
>>  _address = address;
>>  _port = port;
>>  _ssl = ssl;
>> }
>>
>> public void send) {
>> // ..
>> }
>> }
>>
>> The parameter of the constructor is from http request. How can I build
>> this
>> service? I know I can use setters, but I just wanna know how to build a
>> service using constructor.
>>   
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5.0.6-about-Tapestry-ioc-tf4820490.html#a13792550
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5.0.6 about Tapestry ioc

2007-11-16 Thread Chris Lewis
I'm not sure I understand the constructor parameters. Do you mean they 
come from some other object (HttpRequest)? If so, why not just take 
HttpRequest as a constructor argument? If you do that then you can auto 
bind this service and IoC will know how to create it. If you insist on 
the parameters currently listed, then you'll need to have a service 
builder method, and inject HttpRequest as an argument into that method.


lyifan wrote:

I want to implement a service:

public interface Transport {
public void send();
}

public class HttpTransport implement Transport {
private String _address;
private int _port;
private boolean _ssl;
public HttpTransport (String address, int port, boolean ssl) {
 _address = address;
 _port = port;
 _ssl = ssl;
}

public void send) {
// ..
}
}

The parameter of the constructor is from http request. How can I build this
service? I know I can use setters, but I just wanna know how to build a
service using constructor.
  



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]