[dba-VB] Using Interfaces

Salakhetdinov Shamil mcp2004 at mail.ru
Wed Oct 9 01:44:48 CDT 2013


 Hello Dan --

Yes, it should work. You can send me your sample project off-line to fix. But I use VS2012. Anyway the issue should have similar solution for VS2010 and VS2012.

So you have a project B, which referencing project A

B -> A

but some functionality to call from 'Project A' code is located in 'Project B', and you can't set a reference from 'Project A' to 'Project B'

A -> B

because in this case you'll get a circular reference

B <-> A

and VS2010 etc. do not support circular references.

And you do not want to move code from 'Project B' into a new 'Project C' as that moving would require a lot of work.

So you define an interface in 'Project A', let's call it

IMyCallBackToProjectB

with a method CallMe

then you create a facade class in 'Project B' implementing IMyCallBackToProjectB interface's method CallMe handling instance(s) of 'Project B' classes to be called from 'Project A' code, or just implement that interface in your 'Project B' class, which instance methods/functionality should be called from 'Project A'. And you'll have to add instance reference to IMyCallBackToProjectB interface to all your calls to 'Project A' methods, which need calling back 'Project B' functionality. Or you can just have a global variable ( coding purists keep silent please!) in 'Project A' keeping reference to 'Project B' instance implementing IMyCallBackToProjectB interface. That instance reference can be created on program start-up. Don't forget to set it to null and program exiting, otherwise you'll have a chance to get your program left hanging in memory in 'ghost mode' on exiting.

I hope I haven't made the subject even more obscure than it was presented/discussed here before I have posted these my remarks.

Thank you.

- Shamil
 

Tuesday, October  8, 2013 3:24 PM -05:00 from "Dan Waters" <df.waters at comcast.net>:
>Hello!
>
> 
>
>I've been struggling with using an interface to be able to call a
>referencing project from a referenced project.  In Access you just use the
>Application.run("[ProcedureName]",arg1, arg2 .) statement.  But in VB or C#
>there's not a direct equivalent.
>
> 
>
>This can be done - and using an interface is the way to go.  But I've been
>trying to make this work for 4 days now and I need to reach out to a more
>knowledgeable person than me.
>
> 
>
>The simplest explanation is at:
>http://stackoverflow.com/questions/3765177/solve-circular-references-without
>-introducing-a-new-project.  The 2nd entry has what appears to be a simple
>explanation of what to do.  I can make the interface, and the procedure
>which implements it, but the other 2 parts I can't make work.
>
> 
>
>If you'd like to try this let me know.  I've put together a small VB app (VS
>2010) which has all the pieces which I can email as an attachment.
>
> 
>
>Thanks!
>
>Dan 
>
> 
>
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com
>


-- 
Салахетдинов Шамиль


More information about the dba-VB mailing list