What is the proper way to do that?
Let's say we have some third party library in our project and we need to provide an access to some controls which are sealed.
New widgets will be created and added to the application using MEF and they should be able to import some controls from the core application.
So how to export those controls properly?
If you cannot modify the original class (e.g. ThirdPartyComponent), then you can do the export via a property on another class (e.g. ThirdPartyComponentExporter):
public class ThirdPartyComponentExporter
{
[Export(typeof(ThirdPartyComponent))]
public ThirdPartyComponent Foo
{
get
{
return new ThirdPartyComponent();
}
}
}
For visual controls, you may have to use CreationPolicy.NonShared to prevent MEF from reusing the same instance in different locations.
What about wrapping the third party controls in "export" classes and then access this control through the wrapper?
Related
I need to extend spring data in order to support my own custom backend. From the spring data website, it seems that it is possible to add community modules to the framework, which in turn enables you to support a custom backend. However, I can't seem to find some code examples/docs illustrating the module implementation mechanism.
Even a basic example using a file-based persistence would be very helpful.
You just have to extend it then you can override the methods and add your own. If you're using IntelliJ, just implement/extend (for example) CrudRepository, execute Generate Code and select Implement methods or Override methods.
public MyRepository extends CrudRepository<T, Long>{
//in Mac, you press command + N. Then select Override methods.
//in Windows, I don't think Generate Method is given a shortcut. You can find it in the menu bar
}
My multi layer project has Datalayer, services, panel. dataLayer referenced to services, and services referenced to panel. i have an interface in datalayer, some thing like
public interface IJournalEntity
{
...
}
my services has a class that inherited from IJournalEntity,
public class OfflinePaymentService : IOfflinePaymentService, IJournalEntity
{
...
}
when i compile panel layer, unity config raise an error to add reference to data layer, how could i fix withoud referenced that?
You cannot fix without referenced that. The type is unknown to your project if you don't reference it.
Some similar questions:
Access interface methods without referring the class
C# Use a class that implements an interface without adding a reference to the assembly that defines the interface
If your datalayer is defined in a separate dll, you need to put that in Assets/Plugins/. This applied to Unity3D 4.x.
On Unity3D 5.x, just put the dll in Assets will work.
Documentation for plugins
Documentation for plugins on Unity3D 5.x
We have an Eclipse IDE application on 3.x that uses various newWizards to allow the user to create different files. Although these files differ slightly contentwise, the structure of the wizards is quite similar.
Thus, a sound object-oriented approach would be to instantiate different wizards from the same class and initialize them with different data.
Problem:
To decide what wizard needs which data we need a way to distinguish the different already instantiated wizards (e.g during the call to the init method of the wizard).
Is there any way to do so? It would e.g. help if somebody knows a way to get the wizard's id defined in the extension point from within the instantiated wizard.
If your wizard implements IExecutableExtension, it will be passed the configuration element that represents the extension for which it is created.
You can also use extension factories in that you specify a type that implements IExecutableExtensionFactory.
The interface allows you to control how the instances provided to extension-points (wizards in your case) are created.
Extension example:
<extension point="org.eclipse.ui.wizards">
<newWizard
name="..."
class="com.example.WizardFactory">
</newWizard>
Note that the extension factory may also implement IExecutableExtension to gain access to extension attributes before creating the extension's executable class.
I'm trying to get my feet wet with GWT to see if migrating will work out. I usually try the more difficult parts first to make sure I can finish the project. The most difficult part of my project(s) is referencing 3rd party JS libs. In this example I'm trying to use PubNub as much of our platform uses it.
What I'd like to do is create a reusable object that can be used in other GWT projects in need of PubNub. I've got a simple little test running successfully (ie, I've got the basics of JNSI working), but my question is -> where do I put the reference to the 3rd party script in order to create the library/module properly?
Right now I just put the reference to the external scripts in the HTML page in the project, but I'm pretty sure this is incorrect from a reusability perspective, as this lib would be used in other projects, each of which would have their own base HTML page.
I tried putting the reference in the gwt.xml file, but this seems to lose the references (ie my test project no longer works as it did when the scripts were in the HTML page)
Do you have any tips on how to include 3rd party libraries in a reusable GWT library/widget?
Here you have an example using client bundles and script injector, you can use either synchronous loading or asynchronous.
When using sync the external js content will be embedded in the application, otherwise it will be include in a different fragment which will be got with an ajax request.
You can put your api in any server and load it with the ScriptInjector.
public class Example {
public static interface MyApiJs extends ClientBundle {
MyApiJs INSTANCE = GWT.create(MyApiJs.class);
#Source("my_api.js")
TextResource sync();
#Source("my_api.js") // Should be in the same domain or configure CORS
ExternalTextResource async();
}
public void loadSync() {
String js = MyApiJs.INSTANCE.sync().getText();
ScriptInjector.fromString(js).inject();
}
public void loadAsync() throws ResourceException {
MyApiJs.INSTANCE.async().getText(new ResourceCallback<TextResource>() {
public void onSuccess(TextResource r) {
String js = r.getText();
ScriptInjector.fromString(js).inject();
}
public void onError(ResourceException e) {
}
});
}
public void loadFromExternalUrl() {
ScriptInjector.fromUrl("http://.../my_api.js").inject();
}
}
[EDITED]
A better approach is to use a new feature in gwtquery 1.4.0 named JsniBundle. We introduced this feature during the GWT.create conferences at San Francisco and Frankfurt.
With this approach you can insert any external javascript (placed in your source tree or hosted in an external host) as a JSNI block. It has many benefits:
Take advantage of GWT jsni validators, obfuscators and optimizers.
Get rid of any jsni java method when the application does not use it.
The syntax is actually easy:
public interface JQueryBundle extends JsniBundle {
#LibrarySource("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
public void initJQuery();
}
JQueryBundle jQuery = GWT.create(JQueryBundle.class);
jQuery.initJQuery();
One of my team members decided to use autofac on one of our services and because we wanted to try it out we stuck with it.
Now some time has passed and the container setup method has grown! It so big that we are having problems with it.
Splitting it up did not bring the results we looked for. Maybe we are just using it wrong.
So my question is: How can we manage the container setup? Can we dump into XML or are there any other best practices?
There are many ways to manage container setup with autofac.
One of the most common ways is to use a Module and register it with the builder. You can break up multiple groups of registration this way:
public class DALModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register<SomeDataSomething>().As<IDataSomething>();
builder.Register<SomeOtherSomething( c => SomeOtherSomething.Create());
//and so on
}
}
Then register these broken up modules with the builder either via code or XML.
(a simple call to builder.RegisterModule( new DALModule()) would do it here). See the wiki page on Structuring with Modules.
Or, you can use only XML files (or use XML and modules together). See the wiki page on XML config for this.