Moved ColdBox App from lite to Full and now datasource is not working

This is a Coldbox.cdc in config directory

/** structures/arrays to create for configuration
  • coldbox (struct)
  • settings (struct)
  • conventions (struct)
  • environments (struct)
  • wirebox (struct)
  • ioc (struct)
  • debugger (struct)
  • mailSettings (struct)
  • i18n (struct)
  • webservices (struct)
  • datasources (struct)
  • layoutSettings (struct)
  • layouts (array of structs)
  • cacheBox (struct)
  • interceptorSettings (struct)
  • interceptors (array of structs)
  • modules (struct)
  • logBox (struct)
  • flash (struct)
  • orm (struct)
  • validation (struct)

Available objects in variable scope

  • controller
  • logBoxConfig
  • appMapping (auto calculated by ColdBox)

Required Methods

  • configure() : The method ColdBox calls to configure the application.
    Optional Methods
  • detectEnvironment() : If declared the framework will call it and it must return the name of the environment you are on.
  • {environment}() : The name of the environment found and called by the framework.

*/

// Configure ColdBox Application
function configure(){

// coldbox directives
coldbox = {
//Application Setup
appName = “Your app name here”,
eventName = “event”,

//Development Settings
debugMode = true,
debugPassword = “”,
reinitPassword = “”,
handlersIndexAutoReload = true,

//Implicit Events
defaultEvent = “”,
requestStartHandler = “Main.onRequestStart”,
requestEndHandler = “”,
applicationStartHandler = “Main.onAppInit”,
applicationEndHandler = “”,
sessionStartHandler = “”,
sessionEndHandler = “”,
missingTemplateHandler = “”,

//Extension Points
UDFLibraryFile = “includes/helpers/ApplicationHelper.cfm”,
coldboxExtensionsLocation = “”,
modulesExternalLocation = [],
pluginsExternalLocation = “”,
viewsExternalLocation = “”,
layoutsExternalLocation = “”,
handlersExternalLocation = “”,
requestContextDecorator = “”,

//Error/Exception Handling
exceptionHandler = “”,
onInvalidEvent = “”,
customErrorTemplate = “”,

//Application Aspects
handlerCaching = false,
eventCaching = false,
proxyReturnCollection = false
/*
datasources = {
mysite = { name=“contacts”, dbType=“MSSQL”, username="", password=""}
}

Application.cfc (4.73 KB)

Coldbox.cfc (7.03 KB)

ContactDAO.cfc (2.57 KB)

  • How are you creating your DAO? Ie-- is WireBox responsible for instantiation (and autowiring) it?
  • Where in the CFC are you trying to dump out the DSN? Autowiring happens AFTER the init() method has been called. If you want to perform a one-time task on creation of a CFC that uses the autowired properties, create an onDIComplete() method which will automatically be called once by WireBox after the autowiring has happened.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad,
//How are you creating your DAO? Ie-- is WireBox responsible for instantiation (and autowiring) it?
To be honest I’ve copy pasted the code from here wiki.coldbox.org/wiki/Models.cfm and made everything work yesterday only validation was broken
this is my ticket from m yesterday .“https://groups.google.com/forum/#!topic/coldbox/BtWJVce1USY

So, today I’ve copied the model files, handler and copied the configuration settings in now Application and Coldbox files and this problem came up (same settings same everything).

//is WireBox responsible for instantiation (and autowiring) it?
I don’t know …can you please provide Doc link or tutorial for that? Documentation ColdBox site is pretty good the only problem is there is so much of it :).

Where in the CFC are you trying to dump out the DSN?
just after the property is set before init.

component accessors=“true” singleton{

// Dependency Injection
property name=“dsn” inject=“coldbox:datasource:contacts”;
property name=“dsn2” inject=“coldbox:datasource:mysite”;
//property name=“dsn3” inject=“test”;
//ds = getDatasource(‘mysite’);

//WriteDump(dsn);
WriteDump(dsn);
abort;

function init(){
return this;
}

more methods here …

// If you want to perform a one-time task on creation of a CFC that uses the autowired properties, create an onDIComplete()
WHere should I put that method (onDIComplete()) in that same DAO .cfc after init()?

Thanks a lot!

> just after the property is set before init.

Yes, that would be your problem. That is considered part of the components pseudo-constructor and that code is run before Wirebox gets a chance to inject the DNS.

> WHere should I put that method (onDIComplete()) in that same DAO .cfc after init()?

Yes, it should go in the DAO and it doesn’t really matter the order the methods are declared in.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Not working, here is what I did:

component accessors=“true” singleton{
// Dependency Injection
property name=“dsn” inject=“coldbox:datasource:contacts”;
property name=“dsn2” inject=“coldbox:datasource:mysite”;

function init() onDIComplete{
return this;
}

function onDIComplete()
{
//WriteDump(dsn);
WriteDump(dsn);
abort;
}

  1. Why do I have to do this change with DSN with “full faramework” as it was working and still works with Lite version?
  2. Can you please provide some working code/example for this?
  3. Do I need to enable wirebox somehow for full version or it’s already enabled?

Thanks again.

Hi guys, Brad, I am still unable to solve the datasource problem from yesterday and this is decision week for our team to decide if we are going to go with ColdBox or not. I g we can’t solve a basic issue as a datasource than maybe ColdBox is not for us (although you guys have good support and documentation). The last step I can do is to attach this demo project and ask somebody to look into it (it’s based on a contacts Brad’s demo). We also appreciate DI but If we can get the datasource the other way we will use it.

Can you please help?
Project is attached.
p.s. Just to make sure we are clear. We are not asking you to fix our problem, we are asking of you to give us the steps or point us to the right place where we can solve the problem ourselves. I’ve googled, searched your doc’s section and searched your goggle group and didn’t found any resources fir this problem.

Thank you.
Dejan

dejan.zip (289 KB)

Dehan, I’m sorry you’re still having issues. Sorry I never got back to you yesterday-- my day was consumed by meetings.

I downloaded your sample app and ran it. Firstly, the code in your zip file was still dumping DSN in the pseudo constructor (outside of any method) which I told you won’t work. I commented out line 11 of your DAO and uncommented line 16 and the code runs flawlessly for me. I get a dump of the datasource bean. Here is what the top of the DAO looks like now:

component accessors=“true” singleton{

// Dependency Injection
property name=“dsn” inject=“coldbox:datasource:contacts”;
property name=“dsn2” inject=“coldbox:datasource:mysite”;

function init() {// onDIComplete{
return this;
}

//WriteDump(dsn);
//abort;

function onDIComplete()
{
WriteDump(dsn);
abort;
}

1. Why do I have to do this change with DSN with “full faramework” as it was working and still works with Lite version?

Can you show me an example of where data sources worked in ColdBox Lite because they don’t work for me. The ApplicationLoader never reads them

ColdBox Lite is meant to be ONLY MVC conventions. We tossed in a couple goodies like WireBox, but don’t expect much from it. It is purposefully void of many features of the full framework. Now, that being said, the docs for ColdBox Lite don’t actually specify that it won’t read data source settings (it doesn’t, I checked) so it may be an oversight. We can discuss with Luis adding that feature into Lite (though we’re trying hard to keep it from becoming bloated), but in the mean time I noticed that if you put the datasource struct inside the settings structure, WireBox will find it. Honestly, I think it’s more of a fluke, but it does work:

// custom settings
settings = {
datasources = {
contacts = { name=“contacts”, dbType=“MSSQL”, username="", password=""},
mysite = {name=“mySite”, dbType=“mysql”, username=“root”, password=“pass”}
}
};

Technically though, you can always access custom settings (even if they are complex) like so:

property name=“dsn” inject=“coldbox:setting:datasources”;

That will just give you the raw struct instead of creating datasourceBeans out of it.

2. Can you please provide some working code/example for this?

Look at what I’ve pasted above.

3. Do I need to enable wirebox somehow for full version or it’s already enabled?

No, WireBox is enabled by default

~Brad

Hi Brad, thank you for your reply. My test app is now working! :slight_smile:
//Can you show me an example of where data sources worked in ColdBox Lite because they don’t work for me. The ApplicationLoader never reads them

Test APP with lite settings attached

Thanks.
Dejan

helloWorldF.zip (49.4 KB)

Your config in that hello world app is different. Instead of having a separate top-level struct called datasources, you included it as a nested struct inside the main “coldbox” struct. Is that from a sample app somewhere? If so, we should probably fix it since I don’t think settings are supposed to be different between ColdBox full and Lite.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad, I think I tried it first as a separate thing in Lite app and it didn’t work. Then I put it inside the coldbox as the call in DAO says **coldbox:datasource:**contacts. I also look for answers on this Google group before I create a issue/post so maybe somewhere there was that solution.

Thanks.