RE: [coldbox:11182] wirebox scope question

> I understand a singleton to be is a variable that is referred to only once.

A singleton is a class which is only instantiated once. It typically lives for the life of the application and services all threads. A singleton does not generally store any instance data specific to a given thread.

Examples of singletons in my app are all my services and DAOs. Even if 5 concurrent requests are each creating a separate transient user class, they are all injected with the same instance of my userDAO singleton.

Does that make sense?

As far as why you believe you are persisting your service in the session scope, but it seems to be handling requests from other sessions, I don’t have any answer for you. I would have to ask how you know it is being “shared”. That being said, even if it is, it would not be an issue if all the methods are thread-safe. (Using only variables local to that method)

Thanks!

~Brad

Thanks to everyone for the responses. I think I understand this better now.

If I have a bean or struct defined inside of a service that which I injected as singleton would that cause issues with scoping?

In my service (model.userServices) I’m doing:
THIS.userBean = CreateObject(“component”, “app.bean.user”).init();

THIS.userStruct = structNew();

In my handler when I authenticate I do:
getPlugin(“beanFactory”).populateFromStruct(userServices.userBean, userServices.userStruct);

getPlugin(“sessionStorage”).setVar(“userService”, userServices);

my wirebox:
map(“userServices”).to(“model.userServices”).asSingleton();

When I cut this into production and hit refresh I see the last user logged in so the session information is stepping on top of each other. It worked fine until I’ve tried to convert to wirebox.

Any help appreciated.