RealmObject And Implement Interface - realm

When I applied Realm in my object.
It look Like that:
public class Attribute extends RealmObject implements Parcelable, BaseEntity {}
Give me this error:
error: Only getters and setters should be defined in RealmObject classes
Who can give me the resons and solution. BIG THANKS.
Please help me !

Currently RealmObjects does not support implementing Parcable, and interfaces are only supported if they are empty or contain the getters and setter methods you would otherwise generate.
For Parcable you can consider using Parceler: https://realm.io/docs/java/latest/#parceler
Otherwise we are tracking the issue here: https://github.com/realm/realm-java/issues/878
Supporting interfaces in general will be possible once we implement support for custom methods, that can be tracked here: https://github.com/realm/realm-java/issues/909

Related

Drupal 8 Controllers that extends ControllerBase and dependencies injection

I've seen tons of articles saying that I must use dependency injection in my Druapl8 controllers that extends ControllerBase (implementing "create" function etc...)
However, ControllerBase allready has protected properties for getting common services such as entityTypeManager, etc. directly from the container.
So, can I use $this->entityTypeManager() directly inside a such a controller or do I have to do the whole stuff ("create" funciton etc...) ?
Thanks
Yes you can use some handy function currentUser(), config() and state() amongst others directly inside controller. Downside is it make unit testing harder.

ASP.NET Core MVC application dependency injection issue when using BaseController

Recently i tried to create a MVC application using ASP.NET Core 2.0 and i had some values defined in appsettings.json,
"MySettings": {
"WebApiBaseUrl": "http://localhost:6846/api/"
}
In order to read these values i have added
services.Configure<MySettingsModel>(Configuration.GetSection("MySettings"));
above line in ConfigureServices method in Startup.cs
and in my home controller i have added
private readonly IOptions<MySettingsModel> appSettings;
public HomeController(IOptions<MySettingsModel> app)
{
appSettings = app;
}
MySettingsModel class is just a model with property same as key define in appsettings.json.
by this method i'm able to read the value of this key.
Now my issue is that i want to use this key in many controllers so i don't want to repeat this code in every controller so what i did was i created a BaseConntroller, added its constructor and i got my values there. But when i inherit other controllers with my BaseController , it throws me an error and tells me to generate it's constructor, so basically it tells me to add constructor in every controller which is what i wanted to avoid.
How can i achieve this?
You can see the image for the error
And these are the potential fixes that it shows me.
This is just basic C# inheritance. Derived classes must re-implement constructors on base classes (at least the ones you want or need). The only exception is the empty constructor, which is implicit. In other words, you simply need:
public class HomeController : BaseController
{
public HomeController(IOptions<MySettingsModel> app)
: base(app)
{
}
And, of course, you need to change the accessibility of the base class field to protected instead of private. Otherwise, derived classes will not be able to access it.
Of course, this doesn't really save you that much. However, there's no free lunch here. Like I said, this is a limitation of C#, itself, so you have no choice. Although, it's worth mentioning, that while this can sometimes be annoying, it's actually a kind of useful feature of C#. You can look at any class and see exactly what constructors it has available, without having to trace down all its ancestors.
Actually, there is a good solution here:
https://stackoverflow.com/a/48886242/2060975
I am mostly using this method.
[Authorize]
[ApiController]
public abstract class ApiControllerBase : ControllerBase
{
private IOptions<AppSettings> _appSettings;
protected IOptions<AppSettings> appSettings => _appSettings ?? (_appSettings = (IOptions<AppSettings>)this.HttpContext.RequestServices.GetService(typeof(IOptions<AppSettings>)));
...
}
I hope it helps someone:)

Class with PersistenceCapable annotation gets Attempt to store an instance of a non persistable type

Using ObjectDB
[ObjectDB 2.4.1] javax.jdo.JDOUserException
Attempt to store an instance of a non persistable type com.A
#PersistenceCapable
public abstract class B
{
...
#Embedded
protected com.A a = new A();
}
Unfortunately we have been using class A from a library for many years and don't have source available anymore and I cannot put PersistenceCapable annotation on com.A.java. What can I do?
Edit
I think the answer is to add package.jdo for class A. But I still don't understand why is JDO making me either add annotation or make an entry in .jdo file for every class that i want to persist. I wish this could somehow be driven by Serializable interface.
Serialization in ObjectDB is disabled by default, in order to encourage using JPA/JDO persistable types (entity classes, persistence capable classes, embeddable classes), which are more efficient, whenever possible.
However, when serialization is required you can enable it, as explained in the ObjectDB manual.
and then you should be able to store instances of serializable instances in your ObjectDB database.

Add Extension Method to MembershipProvider

I am currently working on a Custom MembershipProvider implementation. But I need additional methods. I would like to call those methods directly on the Membership object within my Controller like this:
Membership.DoStuff()
Is it possible to do that with an extension method? Where would I start?
thanks!
learning more about extension methods is a good start. Please refer to following articles
http://technico.qnownow.com/2012/03/17/how-to-create-extension-methods-in-net/
extension methods (MSDN)
Why don't you add it directly to you class (which have the custom MemebershipProvider) then cast the membership clasd to your then you will find it.
If you asking about the extension methods it should work on any class, so the answer to your question is Yes.
After trying a lot of examples I have found this post where they state that you cannot write extension methods to a static class.
Membership is a static class and you cannot extend it.
yes, Membership is extensible, but you don't extends static class Membership (because it's impossible), you must extends abstract class MembershipProvider, and calls extension methods like Membership.Provider.DoStuff().
For example:
extension class
namespace Infrastructure.Extensions
{
public static class MembershipProviderExtensions
{
public static void DoStuff(this MembershipProvider provider)
{
// do stuff
}
}
}
in your code
using Infrastructure.Extensions;
...
Membership.Provider.DoStuff()
...

Flex: How do you list private attributes of a class?

I try to serialize objects with their private attributes, in Flex.
The introspection API does not seem to allow it:
"The describeType() method returns only public members. The method does not return private members of the caller's superclass or any other class where the caller is not an instance."
Is there another way for an instance to know the name of its private members?
Unfortunately, the describeType() method is the only way to do introspection in Flex. People have written wrappers around it, and if you want to do introspection then I'd recommend as3-commons-reflection, but there is no way to list the private attributes of a class and no way to access them even if you could list them.

Resources