Use DI Nodeset instead of Standard Nodeset http://opcfoundation.org/UA/ - opc-ua

I working with Open62541-Lib. When i Creat Objects with UA_Server_addObjectNode() or UA_Server_addVariableNode() they always get Namespace 0 and belongs to http://opcfoundation.org/UA/. Can i define another Namespace in the Code, so every created Node refers to the DI Nodeset?
I used NodesetCompiler, its create a .c and .h data as Schema from DI-Nodeset and i only can load them as empty Nodes.

Related

Using Zenject to inject an implementation with interfaces

I'm trying to use Zenject in Unity. I have an interface and several implementations of it.
I want to inject with ID but also that the implementation will have the tick interface since it's not a MonoBehaviour.
So I have an IAttacker interface and a MeleeAttackImpl implementation.
Container.Bind<IAttacker>().WithId(AttackerTypeEnum.MELEEE).To<MeleeAttackImpl>().AsTransient();
I want to add
Container.BindInterfacesTo<MeleeAttackImpl>().AsTransient();
But it creates 2 different objects instead of instances that have the Tick interface and bind them to IAttacker.
If you want to bind an interface to a determined implementation, why do you use two bindings?
If you want only one instance of the object I would try:
Container.BindInterfacesAndSelfTo<MeleeAttackImpl>().AsSingle();
or:
Container.Bind<IAttacker>().To<MeleeAttackImpl>().AsSingle();
As Single() In the case you need the same instance provided from the container along the app (like a singleton).
From the documentation:
"AsTransient - Will not re-use the instance at all. Every time ContractType is requested, the DiContainer will execute the given construction method again."
Many times intance is created in the binding itself. So maybe from the two binding two instances are created, one from each binding.
In case you need to create instances dynamically with all their dependencies resolved, what you need a is Factory.

Data property with d2rq

I am using the D2RQ Language to create the mapping file. I have a class Persona with this defination:
# Table persone
map:Persona a d2rq:ClassMap;
d2rq:dataStorage map:database;
d2rq:uriPattern "persona/##persona.cognome_persona##";
d2rq:class prova_rules_M:Persona;
.
I would like to create a data_property called "anni_persona" for this class. How can I do? Can anyone help me with the syntax?
Thank you!
Properties don't "belong" to classes in RDF or OWL. Instead, properties may have domains and ranges, which specifies that the subject or object of a triple with the property belongs to a certain class or datatype. E.g., if we say that the domain of hasName is Agent, then whenever we see "x hasName {something}", then we can infer that "x rdf:type Agent". It sounds like you're trying to say there is a property anni_persona, and that its domain is Persona. That's just a matter of asserting anni_persona rdfs:domain Persona somewhere.
Now, to get values from the database table into RDF data, I think that you'll just want to take a look at section 6 in the documentation:
6. Adding properties to resources (d2rq:PropertyBridge).
A d2rq:PropertyBridge relates a database column to an RDF property.
Property bridges are used to attach properties to the RDF resources
created by a class map. The values of these properties are often
literals, but can also be URIs or blank nodes that relate the resource
to other resources, e.g. the value of a paper's :author property could
be a URI representing a person.
If the one of the columns used in a property bridge is NULL for some
database rows, then no property is created for the resources
corresponding to these rows.
Based on the examples in that documentation, it looks like you'd end up with something like:
map:AnniPersona a d2rq:PropertyBridge ;
d2rq:belongsToClassMap map:Persona ;
d2rq:property :anni_persona ;
d2rq:column "Persone.Anni" .

Getting exported part instance from MEF container

How I can the existing instance of an exported part in MEF container . If I have class A which was composed in the container , I need in some places in my code to get the instance , if I call GetExortedValue() , then if class A signed with CreationPolicy.NonShared , then it'll be instantiated again and I need the current one .
Thanks in advance ...
Obviously calling GetExportedValue<T> on your container could result on the generation of a new instance of T (depending on the CreationPolicy used for the part), but there is an option to call GetExport<T> which will return you a Lazy<T> instance. This is the singular part that is generated and only generated the once:
var part = container.GetExport<IMyInterface>();
In the above example, part would be an instance of Lazy<IMyInterface>, so when you first access part.Value, the delegate bound in the Lazy<IMyInterface> calls back to the container to create and compose the IMyInterface instance and is returned. Subsequent calls to part.Value will always return this same instance.

CodeDom - Linking multiple classes within a single Assembly

I have a C# application that I am trying to re-create through the use of CodeDom. This application has four classes inside of it. If I were to go into this applications directory, I would find the project file (App.csproj), and if I were to start this project file, all four classes would load together. Furthermore, if I were to build this application, all four classes would build together.
My Question: How on earth can I create this functionality through the use of CodeDom?
I have sucessfully created one of the four classes using CodeDom, but how can I go about creating the next three classes (and linking them) to the first class that I already created?
I know this may sound confusing but I will explain more if necessary.
If the classes are in the same namespace you can add them all to one CodeNamespace object and generate the code from that.
If there in different namespaces you can add the namespace of the other Classes to your first class by adding the namespaces reference of the other class's to the namespace object you are working in:-
// Add the Namespace of the other class to the current namespace onject
defaultNameSpace.Imports.Add(new CodeNamespaceImport("Project.Namespace.Namespace"));
Where defaultNameSpace is a type of CodeNamespace. The first Class you have built is added to this CodeNamespace object as below and then the code is generated from that :-
defaultNameSpace.Types.Add(mainClass);
mainClass being a type of CodeTypeDeclaration.
Hope this helps.

How can I add an existing instance to a MEF catalog?

I have an object instance, and I want to end up with a MEF catalog that contains that object instance, exported as a specific interface type. How can I do this?
TypeCatalog doesn't seem workable here, because (a) it creates a new instance instead of using an existing one, and (b) it requires the type to have an [Export] attribute. In my case, the instance comes from MEF's metadata system, so MEF creates the underlying type and I can't add attributes to it.
As far as I can tell, the usual advice is, if you've got an existing instance, you should add it to the container (e.g. via CompositionBatch), not to the catalog. But when I add this instance, I'm also adding an entire AssemblyCatalog worth of types, all in the same operation. I'll also want to be able to remove all of these types later. It makes more sense to me to bundle everything into an AggregateCatalog. That way, I can add both the assembly and the instance in one atomic operation, and I can remove them all again the same way.
For example:
// Bootstrapper code to initialize MEF:
public void Configure() {
_selectedGameCatalog = new AggregateCatalog();
var globalCatalog = new AggregateCatalog(_selectedGameCatalog);
_container = new CompositionContainer(globalCatalog);
// ... more MEF initialization ...
}
// Sometime later, I want to add more stuff to the MEF ecosystem:
public void SelectGame(Lazy<Game, IGameMetadata> entry) {
var newCatalog = new AggregateCatalog();
// Make the assembly available to import:
newCatalog.Catalogs.Add(new AssemblyCatalog(entry.Value.GetType().Assembly));
// I also want the metadata to be available to import:
IGameMetadata metadata = entry.Metadata;
newCatalog.Catalogs.Add(MakeCatalogFromInstance<IGameMetadata>(metadata));
// Replace whatever game was selected before:
_selectedGameCatalog.Catalogs.Clear();
_selectedGameCatalog.Catalogs.Add(newCatalog);
}
The part I don't know how to do is "MakeCatalogFromInstance". How can I create a catalog that contains an existing instance (registered as a specific type)?
Or, alternatively, if I'm going about this all wrong, is there a better way to plug an entire catalog and an existing instance all into MEF at the same time, with the ability to unplug them all again later and replace them with something else?
I think it's probably best to add the types to the catalog and then add the instance to the container.
Catalogs contain part definitions. Part definitions are used to create parts. (The types for this are ComposablePartDefinition and ComposablePart.) So you could theoretically write your own catalog and a part definition that always returned a part corresponding to the instance when CreatePart was called. But catalogs weren't really designed to be used this way.
For prosperity...
MEF devivides the chores of what type info is to be used (catalog) from the actual running object instances (container). To me it is a logical descicion, especially when you setup a more complex MEF environment in your application.
If you want the ability to 'change' containers on the fly, I would suggest you try to use hierarchical containers. The root catalog/container is filled with static types and any of the child containers can be filled with each specific set of meta types you need for your game.
Hope it helps,
Marc