native DI DSL

question regarding the new Coldbox 2.6.2 model integration. if I want
an instance of a model service in my handler would I just give a type
model in my cfproperty attribute, and everything works out?

eg.

<!--- Dependencies --->
<cfproperty name="SomeService" type="model" scope="instance">

and obviously name my CFC SomeService.cfc within my model directory?

thanks

That’s it!!

Also, remember to look at model mappings, so you can create aliases for your models.

ahh! that's killer. not config beans??

super slick man!

thanks

actually do I have to create model mappings? or does coldbox just look
for the name of the CFC in the models directory if I don't?

If you don’t create a mapping, then the name will be matched to whatever exists in the model directory. Example:

/model

  • Book.cfc
    /security
  • SecurityService.cfc

If I want book: getModel(‘Book’)
If I want the security service: getModel(‘security.SecurityService’)

Now, the best practice is to create mappings for model objects that do not exist in the root. So if you want to refactor them or change their names or whatever, you basically just change the mappings file and not the actual code that uses it. So overall, I would suggest you use model mappings for objects in directories inside the model folder.

sounds good. thats what I thought (or at least hoped). :slight_smile:

But one more newb question. Why do I see you creating the instance
scope structure in some CFCs and not others...? Is there places
(models, handlers, plugins) I need to do this and not others?

eg.

<cfscript>
//instance scope
instance = structnew();
</cfscript>

thanks again

The instance scope is already created on all handlers, plugins and interceptors. You do not need to recreate it, but just use it.

See the reserved words and functions guide.http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbReservedGuide

All,

I'm getting this error with attempting model integration:

Element SOMESERVICE is undefined in a Java object of type class
[Ljava.lang.String;.

within my otherService class I have the following...

<!--- Dependencies --->
<cfproperty name="SomeService" type="model" scope="instance" />

// implementation

<cfset var user = instance.SomeService.getUser(arguments) />

any thoughts here, I know this leads back to my original question on
this thread, but I hadn't tested the service yet. Not sure what the
issue is here... It seems as though Im not properly getting and
"instance" of my service (someService)

thanks

I was getting that too, so I added the autowire attribute to my handler and re-init’ed the framework. This seemed to fix it. Why it fixed it, I’m not totally sure, but it fixed it.

@ Jonathan thanks,

however this didn't solve my problem, I'm trying to autowire a model
service into another model service. I don't think the handler has
anything to do with it besides instantiating the call via getModel().
I'm trying to test a method within one of my services that is
dependent on another service.

any other thoughts?

thanks much

@salomoko

Please read this guide, may be something your are missing that’s why having object not found issue
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbModelGuide

If still there problem then please let us provide some detail to reproduce your issue on our end.

Thanks
Sana

thanks sana,

in the case of the simple example given on that page. I'm doing
exactly what the UserService is! In addition, is the example
leveraging coldspring or any other DI for the UserGateway object? In
the UserService all that is declared is the cfproperty, as in my case.
The example "places" the UserGateway into the "instance" scope of the
UserService cfc and away it goes.. I have that same exact setup!

What leads me to the question of other DI frameworks acting upon those
objects is this statement:
"Below you will learn how to wire up dependencies AFTER the object
get's created ". I believe coldspring will "create" then inject into
your dependencies...? Is this not the case for the "built in DI DSL"
of coldbox?

any thoughts?

Oh yeah…correct me if I’m wrong…but what the example doesn’t say is that you need to set up your autowire interceptor in the ColdBox config for that example to work.

done.

I can autowire handlers and plugins just fine. it's injecting
instances of models to models is where I keep getting object not found
issues... I'm not to clear on how integrated coldbox DI DSL is with
coldspring or lightwire... I'm trying to get away from a coldspring
bean definition file, and strictly use coldbox native tools...

thanks though Jonathan. appreciate your input.

sal-

I haven’t played very much with the DI DSL yet, but I’m pretty sure that you must have either ‘lightwire’ or ‘coldspring’ setup as your IOCFramework (setting in coldbox.xml).

I wish I could be more help. For what it’s worth though, last weekend I went through my site and completely replaced ColdSpring with the new model stuff and deleted my ColdSpring folder, my ColdSpring config file, and removed my IOC settings when I was finished.

I saw the error you are seeing several times during that process, but changed so many things I don’t know exactly why the object in question wasn’t being injected and what changes I made fixed it. Stay the course!

Does that mean that you don’t have either?

Assuming the answer to that is ‘yes’, I’m betting that it also means that you do not have any properties set as type=“ioc” or type=“ioc:bean”.

sal, if you’re using anything with type=“ioc” or type=“ioc:bean”, then you’d need either ‘coldspring’ or ‘lightwire’ setup as the IOCFramework. Otherwise, from what Jonathan is saying, it appears that you do not need it.

That’s right…

I’m not using IOC (unless you recognize ColdBox as my IOC Framework). Now, in my code i’ve started using cfproperty with the following types: ocm (the new TransferLoader blows my socks off), model, coldbox:plugin:{…}, coldbox:setting:{…}, coldbox:datasource:{…}

nope. within my one service all I have is:

<cfproperty name="UserService" type="model" scope="instance" />

I can autowire native plugins into my model, objects from cache, I
just cannot autowire a plain jane component model...

@ Jonathan, since you removed your IoC layer, do you have any model to
model dependencies, or service to service dependencies? if so how are
you handling instantiation or injection?

thanks